diff --git a/cmd/gosdn-tview/app.go b/cmd/gosdn-tview/app.go new file mode 100644 index 0000000000000000000000000000000000000000..63f429693963ebec249ef10397ba335f8fdbf5ff --- /dev/null +++ b/cmd/gosdn-tview/app.go @@ -0,0 +1,25 @@ +package main + +import "github.com/rivo/tview" + +type view interface { + GetContent() tview.Primitive +} +type App struct { + app *tview.Application +} + +func NewApp() *App { + a := &App{ + app: tview.NewApplication(), + } + return a +} + +func (a *App) setView(v view) { + a.app.SetRoot(v.GetContent(), true) +} + +func (a *App) Run() error { + return a.app.Run() +} diff --git a/cmd/gosdn-tview/gosdntview b/cmd/gosdn-tview/gosdntview new file mode 100755 index 0000000000000000000000000000000000000000..077fdae1e7ae273c1b52b2b9edb10e50c8df8691 Binary files /dev/null and b/cmd/gosdn-tview/gosdntview differ diff --git a/cmd/gosdn-tview/main.go b/cmd/gosdn-tview/main.go new file mode 100644 index 0000000000000000000000000000000000000000..3c5fb43284cc024007161ff980db5371de518a19 --- /dev/null +++ b/cmd/gosdn-tview/main.go @@ -0,0 +1,9 @@ +package main + +import "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/views" + +func main() { + app := NewApp() + app.setView(views.NewMainView()) + app.Run() +} diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go new file mode 100644 index 0000000000000000000000000000000000000000..e69223dfa28e030627b1e0fed63a5b2f1881f8ba --- /dev/null +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -0,0 +1,37 @@ +package views + +import ( + "github.com/gdamore/tcell" + "github.com/rivo/tview" +) + +type CommandListView struct { + rootNode *tview.TreeNode + commandsTree *tview.TreeView +} + +func NewCommandListView(rootTitle string) *CommandListView { + + v := &CommandListView{} + v.rootNode = tview.NewTreeNode(rootTitle) + v.commandsTree = tview.NewTreeView() + v.commandsTree. + SetRoot(v.rootNode). + SetTitle("Commands"). + SetBorder(true). + SetBorderColor(tcell.ColorSteelBlue) + + return v +} + +func (c *CommandListView) GetContent() tview.Primitive { + return c.commandsTree +} + +func (v *CommandListView) GetCommands(path string) { + //TODO: change to use commandlist +} + +func (v *CommandListView) SelectedFunc() { + //TODO: call GRPC calls for the selected item +} diff --git a/cmd/gosdn-tview/views/mainView.go b/cmd/gosdn-tview/views/mainView.go new file mode 100644 index 0000000000000000000000000000000000000000..8db872954559445cd4d6881537ae2a0abc7042dc --- /dev/null +++ b/cmd/gosdn-tview/views/mainView.go @@ -0,0 +1,43 @@ +package views + +import "github.com/rivo/tview" + +type MainView struct { + pages *tview.Pages + mainFlexBox *tview.Flex + commandsListView *CommandListView + resultAndInputView *ResultAndInputView +} + +func NewMainView() *MainView { + v := &MainView{} + v.pages = tview.NewPages() + v.resultAndInputView = NewResultAndInputView() + v.commandsListView = NewCommandListView("") + v.commandsListView.GetCommands("../") + + v.mainFlexBox = createFlexBox(tview.FlexColumn) + + commandsFlexBox := createFlexBox(tview.FlexRow) + commandsFlexBox.AddItem(v.commandsListView.GetContent(), 0, 40, true) + + resultAndInputFlexBox := createFlexBox(tview.FlexRow) + resultAndInputFlexBox.AddItem(v.resultAndInputView.GetContent(), 0, 10, false) + + v.mainFlexBox. + AddItem(commandsFlexBox, 0, 1, true). + AddItem(resultAndInputFlexBox, 0, 4, false) + + v.pages.AddPage("main", v.mainFlexBox, true, true) + + return v +} + +func (mv *MainView) GetContent() tview.Primitive { + return mv.pages +} + +func createFlexBox(direction int) *tview.Flex { + fb := tview.NewFlex().SetDirection(direction) + return fb +} diff --git a/cmd/gosdn-tview/views/resultAndInputView.go b/cmd/gosdn-tview/views/resultAndInputView.go new file mode 100644 index 0000000000000000000000000000000000000000..b16b10427aadd19ffb5d8963ff2131ca17cd5337 --- /dev/null +++ b/cmd/gosdn-tview/views/resultAndInputView.go @@ -0,0 +1,28 @@ +package views + +import ( + "github.com/gdamore/tcell" + "github.com/rivo/tview" +) + +type ResultAndInputView struct { + resultAndInputView *tview.TextView +} + +func NewResultAndInputView() *ResultAndInputView { + v := &ResultAndInputView{} + v.resultAndInputView = tview.NewTextView() + v.resultAndInputView. + SetDynamicColors(true). + SetRegions(true). + SetScrollable(true). + SetTitle("Result"). + SetBorder(true). + SetBorderColor(tcell.ColorSteelBlue) + + return v +} + +func (r *ResultAndInputView) GetContent() tview.Primitive { + return r.resultAndInputView +}