diff --git a/cmd/gosdn-tview/app/app.go b/cmd/gosdn-tview/app/app.go index 668276b8530ba88b709be0ec439dcf4d68dfca22..d8e9772d64646567ea861a49c708ed164e18b4d1 100644 --- a/cmd/gosdn-tview/app/app.go +++ b/cmd/gosdn-tview/app/app.go @@ -28,6 +28,10 @@ func (a *App) Stop() { a.app.Stop() } +func (a *App) Draw() { + a.app.Draw() +} + func (a *App) SetFocus(v tview.Primitive) { a.app.SetFocus(v) } diff --git a/cmd/gosdn-tview/views/gRPCStatusView.go b/cmd/gosdn-tview/views/gRPCStatusView.go new file mode 100644 index 0000000000000000000000000000000000000000..1c6020b6732aed6616928823b2906de196f963fb --- /dev/null +++ b/cmd/gosdn-tview/views/gRPCStatusView.go @@ -0,0 +1,49 @@ +package views + +import ( + "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app" + "github.com/rivo/tview" + "google.golang.org/grpc" + "time" +) + +type GRPCStatusView struct { + gRPCStatusView *tview.TextView +} + +//TODO: change to grpcStatusView +func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView { + //TODO: change to uses FlexBox if there is more to display in the header + sv := &GRPCStatusView{ + gRPCStatusView: tview.NewTextView(), + } + + sv.gRPCStatusView. + SetRegions(true). + SetBorder(true). + SetTitle("gRPC") + + sv.gRPCStatusView.SetChangedFunc(func() { + app.Draw() + }) + + go goSDNTicker(sv, conn) + + return sv +} + +func (sv *GRPCStatusView) GetContent() tview.Primitive { + return sv.gRPCStatusView +} + +func (sv *GRPCStatusView) SetContent(s string) { + sv.gRPCStatusView.Clear() + sv.gRPCStatusView.SetText(s) +} + +func goSDNTicker(sv *GRPCStatusView, conn *grpc.ClientConn) { + ticker := time.NewTicker(5 * time.Second) + for range ticker.C { + sv.SetContent(conn.GetState().String()) + } +} diff --git a/cmd/gosdn-tview/views/headerView.go b/cmd/gosdn-tview/views/headerView.go index 221c753218c50563238d1759713e5a6c7fc22386..67034bb6492f01563321a8cd777323367689685b 100644 --- a/cmd/gosdn-tview/views/headerView.go +++ b/cmd/gosdn-tview/views/headerView.go @@ -2,12 +2,12 @@ package views import "github.com/rivo/tview" -var goSDNAscii string = ` ____ ____ _ _ - __ _ ___/ ___|| _ \| \ | | - / _ |/ _ \___ \| | | | \| | - | (_| | (_) |__) | |_| | |\ | - \__ |\___/____/|____/|_| \_| - |___/ ` +var goSDNAscii = ` ____ ____ _ _ _ _ _ _ _ ____ _ _ _ + __ _ ___/ ___|| _ \| \ | | | | | | ___ ___| |__ ___ ___| |__ _ _| | ___ | _ \ __ _ _ __ _ __ ___ ___| |_ __ _ __| | |_ + / _ |/ _ \___ \| | | | \| | _____ | |_| |/ _ \ / __| '_ \/ __|/ __| '_ \| | | | |/ _ \ | | | |/ _ | '__| '_ _ \/ __| __/ _ |/ _ | __| +| (_| | (_) |__) | |_| | |\ | |_____| | _ | (_) | (__| | | \__ \ (__| | | | |_| | | __/ | |_| | (_| | | | | | | | \__ \ || (_| | (_| | |_ + \__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__| + |___/ ` type HeaderView struct { headerFlex *tview.Flex diff --git a/cmd/gosdn-tview/views/mainView.go b/cmd/gosdn-tview/views/mainView.go index 7ece090a90f8145535634d0fe3b4dd165f930341..b5123b89e469a5100aa2fd76c1fa5ee465c5e696 100644 --- a/cmd/gosdn-tview/views/mainView.go +++ b/cmd/gosdn-tview/views/mainView.go @@ -12,7 +12,7 @@ type MainView struct { commandsListView *CommandListView resultAndInputView *ResultAndInputView headerView *HeaderView - goSDNStatusView *GoSDNStatusView + goSDNStatusView *GRPCStatusView } func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { @@ -22,7 +22,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { commandsListView: NewCommandListView(), resultAndInputView: NewResultAndInputView(), headerView: NewHeaderView(), - goSDNStatusView: NewGoSDNStatusView(conn), + goSDNStatusView: NewGRPCStatusView(app, conn), } mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn) diff --git a/cmd/gosdn-tview/views/statusView.go b/cmd/gosdn-tview/views/statusView.go deleted file mode 100644 index 306403945b34fc81d45534fdeb431c9e71925a9c..0000000000000000000000000000000000000000 --- a/cmd/gosdn-tview/views/statusView.go +++ /dev/null @@ -1,48 +0,0 @@ -package views - -import ( - "fmt" - "time" - - "github.com/rivo/tview" - "google.golang.org/grpc" -) - -type GoSDNStatusView struct { - statusGoSDNView *tview.TextView -} - -//TODO: change to grpcStatusView -func NewGoSDNStatusView(conn *grpc.ClientConn) *GoSDNStatusView { - //TODO: change to uses FlexBox if there is more to display in the header - sv := &GoSDNStatusView{ - statusGoSDNView: tview.NewTextView(), - } - - sv.statusGoSDNView. - SetRegions(true). - SetBorder(true). - SetTitle("Status: gRPC") - - go goSDNTicker(sv, conn) - - return sv -} - -func (sv *GoSDNStatusView) GetContent() tview.Primitive { - return sv.statusGoSDNView -} - -func (sv *GoSDNStatusView) SetContent(s string) { - sv.statusGoSDNView.Clear() - sv.statusGoSDNView.SetText(s) -} - -func goSDNTicker(sv *GoSDNStatusView, conn *grpc.ClientConn) { - ticker := time.NewTicker(5 * time.Second) - sv.statusGoSDNView.SetText("???") - for range ticker.C { - sv.statusGoSDNView.Clear() - fmt.Println(sv) - } -}