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

first gosdn-tview prototype

has kind of the same features as gosdn-cli
parent 851a60aa
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
...@@ -27,3 +27,7 @@ func (a *App) Run() error { ...@@ -27,3 +27,7 @@ func (a *App) Run() error {
func (a *App) Stop() { func (a *App) Stop() {
a.app.Stop() a.app.Stop()
} }
func (a *App) SetFocus(v tview.Primitive) {
a.app.SetFocus(v)
}
...@@ -23,7 +23,7 @@ type command struct { ...@@ -23,7 +23,7 @@ type command struct {
Name string Name string
Description string Description string
//CommandType commandType //CommandType commandType
Function func(conn *grpc.ClientConn) Function func(conn *grpc.ClientConn) string
} }
var CommandList = []command{ var CommandList = []command{
...@@ -45,7 +45,7 @@ func Connect() *grpc.ClientConn { ...@@ -45,7 +45,7 @@ func Connect() *grpc.ClientConn {
return conn return conn
} }
func goSDNSayHello(conn *grpc.ClientConn) { func goSDNSayHello(conn *grpc.ClientConn) string {
c := pb.NewGrpcCliClient(conn) c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response. // Contact the server and print out its response.
...@@ -56,11 +56,10 @@ func goSDNSayHello(conn *grpc.ClientConn) { ...@@ -56,11 +56,10 @@ func goSDNSayHello(conn *grpc.ClientConn) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Info("Greeting: ", r.String()) return r.GetMessage()
} }
func goSDNShutdown(conn *grpc.ClientConn) { func goSDNShutdown(conn *grpc.ClientConn) string {
c := pb.NewGrpcCliClient(conn) c := pb.NewGrpcCliClient(conn)
...@@ -72,16 +71,17 @@ func goSDNShutdown(conn *grpc.ClientConn) { ...@@ -72,16 +71,17 @@ func goSDNShutdown(conn *grpc.ClientConn) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Info("Greeting: ", r.GetMessage()) return r.GetMessage()
} }
func goSDNTestDB(conn *grpc.ClientConn) { func goSDNTestDB(conn *grpc.ClientConn) string {
// TODO: fill with code and also see if grpc interface has this stub implemented. // TODO: fill with code and also see if grpc interface has this stub implemented.
return "not implemented yet"
} }
// TAPIGetEdge triggers the GetEdge function of the Ciena // TAPIGetEdge triggers the GetEdge function of the Ciena
// flavoured TAPI client // flavoured TAPI client
func TAPIGetEdge(conn *grpc.ClientConn) { func TAPIGetEdge(conn *grpc.ClientConn) string {
c := pb.NewGrpcCliClient(conn) c := pb.NewGrpcCliClient(conn)
...@@ -93,12 +93,12 @@ func TAPIGetEdge(conn *grpc.ClientConn) { ...@@ -93,12 +93,12 @@ func TAPIGetEdge(conn *grpc.ClientConn) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Info("TAPIGetEdge said: ", r.GetMessage()) return r.GetMessage()
} }
// TAPIGetEdgeNode triggers the GetEdgeNode function of the Ciena // TAPIGetEdgeNode triggers the GetEdgeNode function of the Ciena
// flavoured TAPI client // flavoured TAPI client
func TAPIGetEdgeNode(conn *grpc.ClientConn) { func TAPIGetEdgeNode(conn *grpc.ClientConn) string {
c := pb.NewGrpcCliClient(conn) c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response. // Contact the server and print out its response.
...@@ -109,12 +109,12 @@ func TAPIGetEdgeNode(conn *grpc.ClientConn) { ...@@ -109,12 +109,12 @@ func TAPIGetEdgeNode(conn *grpc.ClientConn) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Info("TAPIGetEdgeNode said: ", r.GetMessage()) return r.GetMessage()
} }
// TAPIGetLink triggers the GetLink function of the Ciena // TAPIGetLink triggers the GetLink function of the Ciena
// flavoured TAPI client // flavoured TAPI client
func TAPIGetLink(conn *grpc.ClientConn) { func TAPIGetLink(conn *grpc.ClientConn) string {
c := pb.NewGrpcCliClient(conn) c := pb.NewGrpcCliClient(conn)
...@@ -126,5 +126,5 @@ func TAPIGetLink(conn *grpc.ClientConn) { ...@@ -126,5 +126,5 @@ func TAPIGetLink(conn *grpc.ClientConn) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Info("TAPIGetLink said: ", r.GetMessage()) return r.GetMessage()
} }
...@@ -28,12 +28,14 @@ func (c *CommandListView) GetContent() tview.Primitive { ...@@ -28,12 +28,14 @@ func (c *CommandListView) GetContent() tview.Primitive {
return c.commandsList return c.commandsList
} }
func (v *CommandListView) GetCommands(app *app.App, conn *grpc.ClientConn) { func (v *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) {
for i, command := range commands.CommandList { for i, command := range commands.CommandList {
f := command.Function f := command.Function
v.commandsList. v.commandsList.
AddItem(command.Name, command.Description, rune('a'+i), func() { AddItem(command.Name, command.Description, rune('a'+i), func() {
f(conn) r := f(conn)
rv.SetContent(r)
}) })
} }
......
...@@ -20,7 +20,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -20,7 +20,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
commandsListView: NewCommandListView(), commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(), resultAndInputView: NewResultAndInputView(),
} }
v.commandsListView.GetCommands(app, conn) v.commandsListView.GetCommands(app, v.resultAndInputView, conn)
commandsFlexBox := createFlexBox(tview.FlexRow) commandsFlexBox := createFlexBox(tview.FlexRow)
commandsFlexBox.AddItem(v.commandsListView.GetContent(), 0, 40, true) commandsFlexBox.AddItem(v.commandsListView.GetContent(), 0, 40, true)
......
...@@ -27,3 +27,8 @@ func NewResultAndInputView() *ResultAndInputView { ...@@ -27,3 +27,8 @@ func NewResultAndInputView() *ResultAndInputView {
func (r *ResultAndInputView) GetContent() tview.Primitive { func (r *ResultAndInputView) GetContent() tview.Primitive {
return r.resultAndInputView return r.resultAndInputView
} }
func (r *ResultAndInputView) SetContent(s string) {
r.resultAndInputView.Clear()
r.resultAndInputView.SetText(s)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment