Skip to content
Snippets Groups Projects
resultAndInputView.go 2.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • package views
    
    import (
    
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    
    	"github.com/gdamore/tcell/v2"
    
    	"github.com/rivo/tview"
    
    	"google.golang.org/grpc"
    
    //ResultAndInputView is an application view to display different other views.
    //Depending on the required features the views are changed.
    
    type ResultAndInputView struct {
    
    	title          string
    
    Malte Bauch's avatar
    Malte Bauch committed
    	pages          *tview.Pages
    	resultView     *tview.TextView
    	pndInputView   *AddPNDView
    	consoleLogView *ConsoleLogView
    
    //NewResultAndInputView creates a new ResultAndInputView
    
    func NewResultAndInputView(title string, app *app.App, commandListView tview.Primitive, conn *grpc.ClientConn) *ResultAndInputView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	rv := &ResultAndInputView{
    
    		title:          title,
    
    Malte Bauch's avatar
    Malte Bauch committed
    		pages:          tview.NewPages(),
    
    		pndInputView:   NewAddPNDView("add PND", app),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		resultView:     tview.NewTextView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		consoleLogView: NewConsoleLogView("logs", app, conn),
    
    Malte Bauch's avatar
    Malte Bauch committed
    	}
    
    	rv.resultView.
    
    		SetDynamicColors(true).
    		SetRegions(true).
    		SetScrollable(true).
    
    		SetTitle(rv.title).
    
    		SetBorder(true)
    
    		AddPage(rv.title, rv.resultView, true, true).
    		AddPage(rv.pndInputView.GetTitle(), rv.pndInputView.GetContent(), true, false).
    		AddPage(rv.consoleLogView.GetTitle(), rv.consoleLogView.GetContent(), true, false)
    
    	rv.pages.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
    		k := event.Key()
    		if k == tcell.KeyESC {
    			app.SetFocus(commandListView)
    		}
    		return event
    	})
    
    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)
    
    
    //GetTitle returns the title of the specific view
    func (rv *ResultAndInputView) GetTitle() string {
    	return rv.title
    }