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
Branches
Tags
3 merge requests!90Develop,!59Resolve "Simple ncurse-alike cli to manage gosdn",!53V.0.1.0 Codename Threadbare
Pipeline #52884 passed
package views
import (
"github.com/rivo/tview"
)
import "github.com/rivo/tview"
var goSDNAscii string = ` ____ ____ _ _
__ _ ___/ ___|| _ \| \ | |
......@@ -12,23 +10,23 @@ var goSDNAscii string = ` ____ ____ _ _
|___/ `
type HeaderView struct {
statusView *tview.Flex
headerFlex *tview.Flex
titleView *tview.TextView
}
func NewHeaderView() *HeaderView {
//TODO: change to uses FlexBox if there is more to display in the header
sv := &HeaderView{
hv := &HeaderView{
titleView: tview.NewTextView(),
}
sv.titleView.
hv.titleView.
SetText(goSDNAscii).
SetTextAlign(tview.AlignCenter).
SetBorder(true)
return sv
return hv
}
func (sv *HeaderView) GetContent() tview.Primitive {
return sv.titleView
func (hv *HeaderView) GetContent() tview.Primitive {
return hv.titleView
}
......@@ -11,7 +11,8 @@ type MainView struct {
mainGrid *tview.Grid
commandsListView *CommandListView
resultAndInputView *ResultAndInputView
statusView *HeaderView
headerView *HeaderView
goSDNStatusView *GoSDNStatusView
}
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(),
commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(),
statusView: NewHeaderView(),
headerView: NewHeaderView(),
goSDNStatusView: NewGoSDNStatusView(conn),
}
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
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)
AddItem(mv.headerView.GetContent(), 0, 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).
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