diff --git a/cmd/gosdn-tview/app/app.go b/cmd/gosdn-tview/app/app.go index e81ececa2e8a4c694ccf888114cd029ec0f32c04..668276b8530ba88b709be0ec439dcf4d68dfca22 100644 --- a/cmd/gosdn-tview/app/app.go +++ b/cmd/gosdn-tview/app/app.go @@ -27,3 +27,7 @@ func (a *App) Run() error { func (a *App) Stop() { a.app.Stop() } + +func (a *App) SetFocus(v tview.Primitive) { + a.app.SetFocus(v) +} diff --git a/cmd/gosdn-tview/grpc/commands.go b/cmd/gosdn-tview/grpc/commands.go index a5c49e552a6d6d0725ae2a1021ab01b9f06fb506..1476e7ef8ac82c7be0671054dd6b3104c2788e7f 100644 --- a/cmd/gosdn-tview/grpc/commands.go +++ b/cmd/gosdn-tview/grpc/commands.go @@ -23,7 +23,7 @@ type command struct { Name string Description string //CommandType commandType - Function func(conn *grpc.ClientConn) + Function func(conn *grpc.ClientConn) string } var CommandList = []command{ @@ -45,7 +45,7 @@ func Connect() *grpc.ClientConn { return conn } -func goSDNSayHello(conn *grpc.ClientConn) { +func goSDNSayHello(conn *grpc.ClientConn) string { c := pb.NewGrpcCliClient(conn) // Contact the server and print out its response. @@ -56,11 +56,10 @@ func goSDNSayHello(conn *grpc.ClientConn) { if err != nil { 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) @@ -72,16 +71,17 @@ func goSDNShutdown(conn *grpc.ClientConn) { if err != nil { 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. + return "not implemented yet" } // TAPIGetEdge triggers the GetEdge function of the Ciena // flavoured TAPI client -func TAPIGetEdge(conn *grpc.ClientConn) { +func TAPIGetEdge(conn *grpc.ClientConn) string { c := pb.NewGrpcCliClient(conn) @@ -93,12 +93,12 @@ func TAPIGetEdge(conn *grpc.ClientConn) { if err != nil { log.Fatal(err) } - log.Info("TAPIGetEdge said: ", r.GetMessage()) + return r.GetMessage() } // TAPIGetEdgeNode triggers the GetEdgeNode function of the Ciena // flavoured TAPI client -func TAPIGetEdgeNode(conn *grpc.ClientConn) { +func TAPIGetEdgeNode(conn *grpc.ClientConn) string { c := pb.NewGrpcCliClient(conn) // Contact the server and print out its response. @@ -109,12 +109,12 @@ func TAPIGetEdgeNode(conn *grpc.ClientConn) { if err != nil { log.Fatal(err) } - log.Info("TAPIGetEdgeNode said: ", r.GetMessage()) + return r.GetMessage() } // TAPIGetLink triggers the GetLink function of the Ciena // flavoured TAPI client -func TAPIGetLink(conn *grpc.ClientConn) { +func TAPIGetLink(conn *grpc.ClientConn) string { c := pb.NewGrpcCliClient(conn) @@ -126,5 +126,5 @@ func TAPIGetLink(conn *grpc.ClientConn) { if err != nil { log.Fatal(err) } - log.Info("TAPIGetLink said: ", r.GetMessage()) + return r.GetMessage() } diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 989fd09755928be1eae2a6aae585e1646c5edc12..cc4dc25028bbbebc9ec404f4d5e6a6fae964e168 100644 --- a/cmd/gosdn-tview/views/commandsListView.go +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -28,12 +28,14 @@ func (c *CommandListView) GetContent() tview.Primitive { 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 { f := command.Function v.commandsList. AddItem(command.Name, command.Description, rune('a'+i), func() { - f(conn) + r := f(conn) + rv.SetContent(r) }) } diff --git a/cmd/gosdn-tview/views/mainView.go b/cmd/gosdn-tview/views/mainView.go index 1e86860c685a10164d5ca7b4148f4c45c6714912..4c251af331037bb0eaa75ff96dab7aa33e041ca6 100644 --- a/cmd/gosdn-tview/views/mainView.go +++ b/cmd/gosdn-tview/views/mainView.go @@ -20,7 +20,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { commandsListView: NewCommandListView(), resultAndInputView: NewResultAndInputView(), } - v.commandsListView.GetCommands(app, conn) + v.commandsListView.GetCommands(app, v.resultAndInputView, conn) commandsFlexBox := createFlexBox(tview.FlexRow) commandsFlexBox.AddItem(v.commandsListView.GetContent(), 0, 40, true) diff --git a/cmd/gosdn-tview/views/resultAndInputView.go b/cmd/gosdn-tview/views/resultAndInputView.go index 89e9d77ba88578437cb6827bab48aafd85e8d2c2..5be8adf8148b63bcb4200b3f544e30973b2caa8f 100644 --- a/cmd/gosdn-tview/views/resultAndInputView.go +++ b/cmd/gosdn-tview/views/resultAndInputView.go @@ -27,3 +27,8 @@ func NewResultAndInputView() *ResultAndInputView { func (r *ResultAndInputView) GetContent() tview.Primitive { return r.resultAndInputView } + +func (r *ResultAndInputView) SetContent(s string) { + r.resultAndInputView.Clear() + r.resultAndInputView.SetText(s) +}