From b65e6f19067a2e398f09d735426461fc506977b7 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Wed, 14 Oct 2020 18:14:17 +0200 Subject: [PATCH] first gosdn-tview prototype has kind of the same features as gosdn-cli --- cmd/gosdn-tview/app/app.go | 4 ++++ cmd/gosdn-tview/grpc/commands.go | 26 ++++++++++----------- cmd/gosdn-tview/views/commandsListView.go | 6 +++-- cmd/gosdn-tview/views/mainView.go | 2 +- cmd/gosdn-tview/views/resultAndInputView.go | 5 ++++ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/cmd/gosdn-tview/app/app.go b/cmd/gosdn-tview/app/app.go index e81ececa2..668276b85 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 a5c49e552..1476e7ef8 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 989fd0975..cc4dc2502 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 1e86860c6..4c251af33 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 89e9d77ba..5be8adf81 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) +} -- GitLab