Skip to content
Snippets Groups Projects
resultAndInputView.go 1.51 KiB
Newer Older
  • Learn to ignore specific revisions
  • package views
    
    import (
    
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    
    	"github.com/rivo/tview"
    )
    
    
    //ResultAndInputView is an application view to display different other views.
    //Depending on the required features the views are changed.
    
    type ResultAndInputView struct {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	pages          *tview.Pages
    	resultView     *tview.TextView
    	pndInputView   *AddPNDView
    	consoleLogView *ConsoleLogView
    
    //NewResultAndInputView creates a new ResultAndInputView
    
    func NewResultAndInputView(app *app.App) *ResultAndInputView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	rv := &ResultAndInputView{
    
    Malte Bauch's avatar
    Malte Bauch committed
    		pages:          tview.NewPages(),
    		pndInputView:   NewAddPNDView(app),
    		resultView:     tview.NewTextView(),
    		consoleLogView: NewConsoleLogView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    	}
    
    	rv.resultView.
    
    		SetDynamicColors(true).
    		SetRegions(true).
    		SetScrollable(true).
    		SetTitle("Result").
    
    		SetBorder(true)
    
    	rv.pages.
    		AddPage("result", rv.resultView, true, true).
    
    Malte Bauch's avatar
    Malte Bauch committed
    		AddPage("addPND", rv.pndInputView.GetContent(), true, false).
    		AddPage("log", rv.consoleLogView.GetContent(), true, false)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	return rv
    
    //GetContent returns the tview.Primitive belonging to the ResultAndInputView
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (rv *ResultAndInputView) GetContent() tview.Primitive {
    
    //ChangeContentView changes the current content (tview.Primitive) that is visible
    //inside this view
    
    func (rv *ResultAndInputView) ChangeContentView(s string) {
    	rv.pages.SwitchToPage(s)
    
    //SetContent sets new string content for the ResultAndInputView
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (rv *ResultAndInputView) SetContent(s string) {
    
    	rv.resultView.Clear()
    	rv.resultView.SetText(s)