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

added grpc Status view

- goroutine not working yet
- renaming required
parent 8e43ff01
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
Pipeline #52884 passed
package views package views
import ( import "github.com/rivo/tview"
"github.com/rivo/tview"
)
var goSDNAscii string = ` ____ ____ _ _ var goSDNAscii string = ` ____ ____ _ _
__ _ ___/ ___|| _ \| \ | | __ _ ___/ ___|| _ \| \ | |
...@@ -12,23 +10,23 @@ var goSDNAscii string = ` ____ ____ _ _ ...@@ -12,23 +10,23 @@ var goSDNAscii string = ` ____ ____ _ _
|___/ ` |___/ `
type HeaderView struct { type HeaderView struct {
statusView *tview.Flex headerFlex *tview.Flex
titleView *tview.TextView titleView *tview.TextView
} }
func NewHeaderView() *HeaderView { func NewHeaderView() *HeaderView {
//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 := &HeaderView{ hv := &HeaderView{
titleView: tview.NewTextView(), titleView: tview.NewTextView(),
} }
sv.titleView. hv.titleView.
SetText(goSDNAscii). SetText(goSDNAscii).
SetTextAlign(tview.AlignCenter). SetTextAlign(tview.AlignCenter).
SetBorder(true) SetBorder(true)
return sv return hv
} }
func (sv *HeaderView) GetContent() tview.Primitive { func (hv *HeaderView) GetContent() tview.Primitive {
return sv.titleView return hv.titleView
} }
...@@ -11,7 +11,8 @@ type MainView struct { ...@@ -11,7 +11,8 @@ type MainView struct {
mainGrid *tview.Grid mainGrid *tview.Grid
commandsListView *CommandListView commandsListView *CommandListView
resultAndInputView *ResultAndInputView resultAndInputView *ResultAndInputView
statusView *HeaderView headerView *HeaderView
goSDNStatusView *GoSDNStatusView
} }
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
...@@ -20,15 +21,16 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -20,15 +21,16 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
mainGrid: tview.NewGrid(), mainGrid: tview.NewGrid(),
commandsListView: NewCommandListView(), commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(), resultAndInputView: NewResultAndInputView(),
statusView: NewHeaderView(), headerView: NewHeaderView(),
goSDNStatusView: NewGoSDNStatusView(conn),
} }
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn) mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
mv.mainGrid. mv.mainGrid.
SetRows(8, 0, 3). SetRows(8, 0, 3).
SetColumns(40, 0). SetColumns(40, 0).
AddItem(mv.statusView.GetContent(), 0, 0, 1, 2, 0, 0, false). AddItem(mv.headerView.GetContent(), 0, 0, 1, 2, 0, 0, false).
AddItem(newPrimitive("Footer"), 2, 0, 1, 2, 0, 0, false) AddItem(mv.goSDNStatusView.GetContent(), 2, 0, 1, 2, 0, 0, false)
mv.mainGrid.AddItem(mv.commandsListView.GetContent(), 1, 0, 1, 1, 0, 0, true). mv.mainGrid.AddItem(mv.commandsListView.GetContent(), 1, 0, 1, 1, 0, 0, true).
AddItem(mv.resultAndInputView.GetContent(), 1, 1, 1, 1, 0, 0, false) AddItem(mv.resultAndInputView.GetContent(), 1, 1, 1, 1, 0, 0, false)
......
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)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment