Skip to content
Snippets Groups Projects
Commit a9135ed1 authored by Malte Bauch's avatar Malte Bauch
Browse files

basic structure for tview application

parent 21eddd61
No related branches found
No related tags found
3 merge requests!90Develop,!59Resolve "Simple ncurse-alike cli to manage gosdn",!53V.0.1.0 Codename Threadbare
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()
}
File added
package main
import "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/views"
func main() {
app := NewApp()
app.setView(views.NewMainView())
app.Run()
}
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
}
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
}
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment