diff --git a/cmd/gosdn-tview/grpc/commands.go b/cmd/gosdn-tview/grpc/commands.go index 1476e7ef8ac82c7be0671054dd6b3104c2788e7f..6eabf835326dcf0a08663bec21632fbc09384744 100644 --- a/cmd/gosdn-tview/grpc/commands.go +++ b/cmd/gosdn-tview/grpc/commands.go @@ -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 { diff --git a/cmd/gosdn-tview/main.go b/cmd/gosdn-tview/main.go index f44ba7ae773dd13513be864e3f1f62461ae42194..36570d4941e3363c9cbe9cf47eb8279570585a7c 100644 --- a/cmd/gosdn-tview/main.go +++ b/cmd/gosdn-tview/main.go @@ -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() } diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 15dd0126d6de234022d730eea46c113dbaef4cd1..8e4009a968d073e70c5da41474daa43ce6e481b2 100644 --- a/cmd/gosdn-tview/views/commandsListView.go +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -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 diff --git a/cmd/gosdn-tview/views/headerView.go b/cmd/gosdn-tview/views/headerView.go new file mode 100644 index 0000000000000000000000000000000000000000..758fc08b692cf6bda9e0800b6ff81e3bb99ce0d0 --- /dev/null +++ b/cmd/gosdn-tview/views/headerView.go @@ -0,0 +1,34 @@ +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 +} diff --git a/cmd/gosdn-tview/views/mainView.go b/cmd/gosdn-tview/views/mainView.go index e2a1c4c42def69e1fd1d192e05f7db9b02fa6dcc..f7ac937e9f8d144d50a24f887f7ee40eae2f2206 100644 --- a/cmd/gosdn-tview/views/mainView.go +++ b/cmd/gosdn-tview/views/mainView.go @@ -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) } diff --git a/cmd/gosdn-tview/views/resultAndInputView.go b/cmd/gosdn-tview/views/resultAndInputView.go index b46ca29e3c32a6bb673ec7c58d020a1d63e4031f..2e0e5f1af5606e11e2db79384cdf79aefd902bfd 100644 --- a/cmd/gosdn-tview/views/resultAndInputView.go +++ b/cmd/gosdn-tview/views/resultAndInputView.go @@ -1,7 +1,6 @@ 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 }