Skip to content
Snippets Groups Projects
consoleLogView.go 1.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package views
    
    
    import (
    	commands "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc"
    	"github.com/rivo/tview"
    	"google.golang.org/grpc"
    )
    
    Malte Bauch's avatar
    Malte Bauch committed
    
    //ConsoleLogView is an application view to create a view for goSDN log messages
    type ConsoleLogView struct {
    	consoleLogView *tview.TextView
    }
    
    //NewConsoleLogView creates a new ConsoleLogView
    
    func NewConsoleLogView(conn *grpc.ClientConn) *ConsoleLogView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	clv := &ConsoleLogView{
    		consoleLogView: tview.NewTextView(),
    	}
    	clv.consoleLogView.
    		SetDynamicColors(true).
    		SetTextAlign(tview.AlignCenter).
    		SetRegions(true).
    		SetBorder(true).
    
    		SetTitle("goSDN Logs")
    
    	commands.GoSDNLogStream(conn, clv.consoleLogView)
    
    Malte Bauch's avatar
    Malte Bauch committed
    
    	return clv
    }
    
    //GetContent returns the tview.Primitive belonging to the ConsoleLogView
    func (clv *ConsoleLogView) GetContent() tview.Primitive {
    	return clv.consoleLogView
    }
    
    //Write implements the io.Writer interface via tview.textView.Write().
    //Gets a string and converts it to a byte slice and writes it to the textView
    //buffer
    func (clv *ConsoleLogView) Write(s string) (n int, err error) {
    	b := []byte(s)
    	return clv.consoleLogView.Write(b)
    }