Skip to content
Snippets Groups Projects
mainView.go 1.22 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
    	mainFlexBox        *tview.Flex
    	commandsListView   *CommandListView
    	resultAndInputView *ResultAndInputView
    }
    
    
    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(),
    		mainFlexBox:        createFlexBox(tview.FlexColumn),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		commandsListView:   NewCommandListView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		resultAndInputView: NewResultAndInputView(),
    	}
    
    Malte Bauch's avatar
    Malte Bauch committed
    	mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
    
    
    	commandsFlexBox := createFlexBox(tview.FlexRow)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	commandsFlexBox.AddItem(mv.commandsListView.GetContent(), 0, 40, true)
    
    
    	resultAndInputFlexBox := createFlexBox(tview.FlexRow)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	resultAndInputFlexBox.AddItem(mv.resultAndInputView.GetContent(), 0, 10, false)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	mv.mainFlexBox.
    
    		AddItem(commandsFlexBox, 0, 1, true).
    		AddItem(resultAndInputFlexBox, 0, 4, false)
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    	mv.pages.AddPage("main", mv.mainFlexBox, true, true)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	return mv
    
    }
    
    func (mv *MainView) GetContent() tview.Primitive {
    	return mv.pages
    }
    
    func createFlexBox(direction int) *tview.Flex {
    	fb := tview.NewFlex().SetDirection(direction)
    	return fb
    }