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