Skip to content
Snippets Groups Projects
consoleLogView.go 958 B
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package views
    
    import "github.com/rivo/tview"
    
    //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() *ConsoleLogView {
    	clv := &ConsoleLogView{
    		consoleLogView: tview.NewTextView(),
    	}
    	clv.consoleLogView.
    		SetDynamicColors(true).
    		SetTextAlign(tview.AlignCenter).
    		SetRegions(true).
    		SetBorder(true).
    		SetTitle("goSDN Logger Output")
    
    	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)
    }