Skip to content
Snippets Groups Projects
consoleLogView.go 1.35 KiB
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package views
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    
    	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 {
    
    	title          string
    
    Malte Bauch's avatar
    Malte Bauch committed
    	consoleLogView *tview.TextView
    }
    
    //NewConsoleLogView creates a new ConsoleLogView
    
    Malte Bauch's avatar
    Malte Bauch committed
    func NewConsoleLogView(title string, app *app.App, conn *grpc.ClientConn) *ConsoleLogView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	clv := &ConsoleLogView{
    		consoleLogView: tview.NewTextView(),
    
    		title:          title,
    
    Malte Bauch's avatar
    Malte Bauch committed
    	}
    	clv.consoleLogView.
    		SetDynamicColors(true).
    
    		SetTextAlign(tview.AlignLeft).
    		SetScrollable(true).
    
    Malte Bauch's avatar
    Malte Bauch committed
    		SetRegions(true).
    		SetBorder(true).
    
    		SetTitle(clv.title)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	commands.GoSDNLogStream(app, 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)
    }
    
    
    //GetTitle returns the title of the specific view
    func (clv *ConsoleLogView) GetTitle() string {
    	return clv.title
    }