Skip to content
Snippets Groups Projects
mainView.go 1.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • package views
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    	"github.com/rivo/tview"
    	"google.golang.org/grpc"
    )
    
    
    type MainView struct {
    	pages              *tview.Pages
    
    	mainGrid           *tview.Grid
    
    	commandsListView   *CommandListView
    	resultAndInputView *ResultAndInputView
    
    	statusView         *HeaderView
    
    Malte Bauch's avatar
    Malte Bauch committed
    func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	mv := &MainView{
    
    Malte Bauch's avatar
    Malte Bauch committed
    		pages:              tview.NewPages(),
    
    		mainGrid:           tview.NewGrid(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		commandsListView:   NewCommandListView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		resultAndInputView: NewResultAndInputView(),
    
    		statusView:         NewHeaderView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    	}
    
    Malte Bauch's avatar
    Malte Bauch committed
    	mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
    
    	mv.mainGrid.
    		SetRows(8, 0, 3).
    		SetColumns(40, 0).
    		AddItem(mv.statusView.GetContent(), 0, 0, 1, 2, 0, 0, false).
    		AddItem(newPrimitive("Footer"), 2, 0, 1, 2, 0, 0, false)
    
    	mv.mainGrid.AddItem(mv.commandsListView.GetContent(), 1, 0, 1, 1, 0, 0, true).
    		AddItem(mv.resultAndInputView.GetContent(), 1, 1, 1, 1, 0, 0, false)
    
    	mv.pages.AddPage("main", mv.mainGrid, true, true)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	return mv
    
    }
    
    func (mv *MainView) GetContent() tview.Primitive {
    	return mv.pages
    }
    
    
    func newPrimitive(text string) tview.Primitive {
    	return tview.NewTextView().
    		SetTextAlign(tview.AlignCenter).
    		SetText(text)