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

fixed grpcStatusView

parent 3587d90b
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
...@@ -28,6 +28,10 @@ func (a *App) Stop() { ...@@ -28,6 +28,10 @@ func (a *App) Stop() {
a.app.Stop() a.app.Stop()
} }
func (a *App) Draw() {
a.app.Draw()
}
func (a *App) SetFocus(v tview.Primitive) { func (a *App) SetFocus(v tview.Primitive) {
a.app.SetFocus(v) a.app.SetFocus(v)
} }
package views package views
import ( import (
"fmt" "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"time"
"github.com/rivo/tview" "github.com/rivo/tview"
"google.golang.org/grpc" "google.golang.org/grpc"
"time"
) )
type GoSDNStatusView struct { type GRPCStatusView struct {
statusGoSDNView *tview.TextView gRPCStatusView *tview.TextView
} }
//TODO: change to grpcStatusView //TODO: change to grpcStatusView
func NewGoSDNStatusView(conn *grpc.ClientConn) *GoSDNStatusView { func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
//TODO: change to uses FlexBox if there is more to display in the header //TODO: change to uses FlexBox if there is more to display in the header
sv := &GoSDNStatusView{ sv := &GRPCStatusView{
statusGoSDNView: tview.NewTextView(), gRPCStatusView: tview.NewTextView(),
} }
sv.statusGoSDNView. sv.gRPCStatusView.
SetRegions(true). SetRegions(true).
SetBorder(true). SetBorder(true).
SetTitle("Status: gRPC") SetTitle("gRPC")
sv.gRPCStatusView.SetChangedFunc(func() {
app.Draw()
})
go goSDNTicker(sv, conn) go goSDNTicker(sv, conn)
return sv return sv
} }
func (sv *GoSDNStatusView) GetContent() tview.Primitive { func (sv *GRPCStatusView) GetContent() tview.Primitive {
return sv.statusGoSDNView return sv.gRPCStatusView
} }
func (sv *GoSDNStatusView) SetContent(s string) { func (sv *GRPCStatusView) SetContent(s string) {
sv.statusGoSDNView.Clear() sv.gRPCStatusView.Clear()
sv.statusGoSDNView.SetText(s) sv.gRPCStatusView.SetText(s)
} }
func goSDNTicker(sv *GoSDNStatusView, conn *grpc.ClientConn) { func goSDNTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
sv.statusGoSDNView.SetText("???")
for range ticker.C { for range ticker.C {
sv.statusGoSDNView.Clear() sv.SetContent(conn.GetState().String())
fmt.Println(sv)
} }
} }
...@@ -2,12 +2,12 @@ package views ...@@ -2,12 +2,12 @@ package views
import "github.com/rivo/tview" import "github.com/rivo/tview"
var goSDNAscii string = ` ____ ____ _ _ var goSDNAscii = ` ____ ____ _ _ _ _ _ _ _ ____ _ _ _
__ _ ___/ ___|| _ \| \ | | __ _ ___/ ___|| _ \| \ | | | | | | ___ ___| |__ ___ ___| |__ _ _| | ___ | _ \ __ _ _ __ _ __ ___ ___| |_ __ _ __| | |_
/ _ |/ _ \___ \| | | | \| | / _ |/ _ \___ \| | | | \| | _____ | |_| |/ _ \ / __| '_ \/ __|/ __| '_ \| | | | |/ _ \ | | | |/ _ | '__| '_ _ \/ __| __/ _ |/ _ | __|
| (_| | (_) |__) | |_| | |\ | | (_| | (_) |__) | |_| | |\ | |_____| | _ | (_) | (__| | | \__ \ (__| | | | |_| | | __/ | |_| | (_| | | | | | | | \__ \ || (_| | (_| | |_
\__ |\___/____/|____/|_| \_| \__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__|
|___/ ` |___/ `
type HeaderView struct { type HeaderView struct {
headerFlex *tview.Flex headerFlex *tview.Flex
......
...@@ -12,7 +12,7 @@ type MainView struct { ...@@ -12,7 +12,7 @@ type MainView struct {
commandsListView *CommandListView commandsListView *CommandListView
resultAndInputView *ResultAndInputView resultAndInputView *ResultAndInputView
headerView *HeaderView headerView *HeaderView
goSDNStatusView *GoSDNStatusView goSDNStatusView *GRPCStatusView
} }
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
...@@ -22,7 +22,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -22,7 +22,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
commandsListView: NewCommandListView(), commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(), resultAndInputView: NewResultAndInputView(),
headerView: NewHeaderView(), headerView: NewHeaderView(),
goSDNStatusView: NewGoSDNStatusView(conn), goSDNStatusView: NewGRPCStatusView(app, conn),
} }
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn) mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment