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

changed from FlexBox to Grid, added Header

parent 8f3d1d99
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
......@@ -35,14 +35,9 @@ var CommandList = []command{
{"tapigetlink", "get list of links", TAPIGetLink},
}
func Connect() *grpc.ClientConn {
func Connect() (*grpc.ClientConn, error) {
address := "localhost:55055"
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatal(err)
}
log.Info("Connected to " + conn.Target())
return conn
return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
}
func goSDNSayHello(conn *grpc.ClientConn) string {
......
......@@ -4,12 +4,18 @@ import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
grpc "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc"
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/views"
"code.fbi.h-da.de/cocsn/gosdn/log"
)
func main() {
conn := grpc.Connect()
conn, err := grpc.Connect()
if err != nil {
log.Fatal(err)
}
app := app.NewApp()
app.SetView(views.NewMainView(app, conn))
app.Run()
app.Stop()
defer app.Stop()
}
......@@ -3,7 +3,6 @@ package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
commands "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"google.golang.org/grpc"
)
......@@ -18,7 +17,6 @@ func NewCommandListView() *CommandListView {
}
cv.commandsList.
SetBorder(true).
SetBorderColor(tcell.ColorSteelBlue).
SetTitle("Commands")
return cv
......
package views
import (
"github.com/rivo/tview"
)
var goSDNAscii string = ` ____ ____ _ _
__ _ ___/ ___|| _ \| \ | |
/ _ |/ _ \___ \| | | | \| |
| (_| | (_) |__) | |_| | |\ |
\__ |\___/____/|____/|_| \_|
|___/ `
type HeaderView struct {
statusView *tview.Flex
titleView *tview.TextView
}
func NewHeaderView() *HeaderView {
//TODO: change to uses FlexBox if there is more to display in the header
sv := &HeaderView{
titleView: tview.NewTextView(),
}
sv.titleView.
SetText(goSDNAscii).
SetTextAlign(tview.AlignCenter).
SetBorder(true)
return sv
}
func (sv *HeaderView) GetContent() tview.Primitive {
return sv.titleView
}
......@@ -8,31 +8,32 @@ import (
type MainView struct {
pages *tview.Pages
mainFlexBox *tview.Flex
mainGrid *tview.Grid
commandsListView *CommandListView
resultAndInputView *ResultAndInputView
statusView *HeaderView
}
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
mv := &MainView{
pages: tview.NewPages(),
mainFlexBox: createFlexBox(tview.FlexColumn),
mainGrid: tview.NewGrid(),
commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(),
statusView: NewHeaderView(),
}
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
commandsFlexBox := createFlexBox(tview.FlexRow)
commandsFlexBox.AddItem(mv.commandsListView.GetContent(), 0, 40, true)
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)
resultAndInputFlexBox := createFlexBox(tview.FlexRow)
resultAndInputFlexBox.AddItem(mv.resultAndInputView.GetContent(), 0, 10, 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.mainFlexBox.
AddItem(commandsFlexBox, 0, 1, true).
AddItem(resultAndInputFlexBox, 0, 4, false)
mv.pages.AddPage("main", mv.mainFlexBox, true, true)
mv.pages.AddPage("main", mv.mainGrid, true, true)
return mv
}
......@@ -41,7 +42,8 @@ func (mv *MainView) GetContent() tview.Primitive {
return mv.pages
}
func createFlexBox(direction int) *tview.Flex {
fb := tview.NewFlex().SetDirection(direction)
return fb
func newPrimitive(text string) tview.Primitive {
return tview.NewTextView().
SetTextAlign(tview.AlignCenter).
SetText(text)
}
package views
import (
"github.com/gdamore/tcell"
"github.com/rivo/tview"
)
......@@ -18,8 +17,7 @@ func NewResultAndInputView() *ResultAndInputView {
SetRegions(true).
SetScrollable(true).
SetTitle("Result").
SetBorder(true).
SetBorderColor(tcell.ColorSteelBlue)
SetBorder(true)
return rv
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment