From c1957eebf70711e91227c53900ef608fcba9b442 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Fri, 16 Oct 2020 17:52:54 +0200 Subject: [PATCH] changed to use pages for resultAndInputView core is working -> now we need the more advanced grpc calls --- cmd/gosdn-tview/main.go | 2 -- cmd/gosdn-tview/views/addPNDView.go | 4 +++ cmd/gosdn-tview/views/commandsListView.go | 4 ++- cmd/gosdn-tview/views/mainView.go | 2 +- cmd/gosdn-tview/views/resultAndInputView.go | 27 +++++++++++++++------ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cmd/gosdn-tview/main.go b/cmd/gosdn-tview/main.go index ef8c54ef9..7f7368547 100644 --- a/cmd/gosdn-tview/main.go +++ b/cmd/gosdn-tview/main.go @@ -15,10 +15,8 @@ func main() { app := app.NewApp() mainView := views.NewMainView(app, conn) - addPNDView := views.NewAddPNDView(app) app.SetRoot(mainView) - app.AddPage("PND", addPNDView) app.Run() defer app.Stop() diff --git a/cmd/gosdn-tview/views/addPNDView.go b/cmd/gosdn-tview/views/addPNDView.go index 0060852ee..7fdf75611 100644 --- a/cmd/gosdn-tview/views/addPNDView.go +++ b/cmd/gosdn-tview/views/addPNDView.go @@ -13,6 +13,10 @@ func NewAddPNDView(app *app.App) *AddPNDView { pndv := &AddPNDView{ addPNDView: tview.NewForm(), } + pndv.addPNDView. + SetBorder(true). + SetTitle("Add new PND") + pndv.addPNDView. AddInputField("Name", "", 20, nil, nil). AddInputField("description", "", 20, nil, nil). diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 16ff032ba..2ab3f9452 100644 --- a/cmd/gosdn-tview/views/commandsListView.go +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -30,7 +30,8 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, conn *grpc.ClientConn) { //TODO: create own command in grpc -> commands cv.commandsList.AddItem("AddPND", "closes the application", '!', func() { - app.SwitchPage("PND") + rv.ChangeContentView("addPND") + app.SetFocus(rv.GetContent()) }) for i, command := range commands.CommandList { @@ -39,6 +40,7 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, AddItem(command.Name, command.Description, rune('a'+i), func() { r := f(conn) rv.SetContent(r) + rv.ChangeContentView("result") }) } diff --git a/cmd/gosdn-tview/views/mainView.go b/cmd/gosdn-tview/views/mainView.go index e69d74dc6..6c95c811c 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 { pages: tview.NewPages(), mainGrid: tview.NewGrid(), commandsListView: NewCommandListView(), - resultAndInputView: NewResultAndInputView(), + resultAndInputView: NewResultAndInputView(app), headerView: NewHeaderView(), footerView: NewFooterView(app, conn), } diff --git a/cmd/gosdn-tview/views/resultAndInputView.go b/cmd/gosdn-tview/views/resultAndInputView.go index 2e0e5f1af..99ae89654 100644 --- a/cmd/gosdn-tview/views/resultAndInputView.go +++ b/cmd/gosdn-tview/views/resultAndInputView.go @@ -1,32 +1,45 @@ package views import ( + "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app" "github.com/rivo/tview" ) type ResultAndInputView struct { - resultAndInputView *tview.TextView + pages *tview.Pages + resultView *tview.TextView + pndInputView *AddPNDView } -func NewResultAndInputView() *ResultAndInputView { +func NewResultAndInputView(app *app.App) *ResultAndInputView { rv := &ResultAndInputView{ - resultAndInputView: tview.NewTextView(), + pages: tview.NewPages(), + pndInputView: NewAddPNDView(app), + resultView: tview.NewTextView(), } - rv.resultAndInputView. + rv.resultView. SetDynamicColors(true). SetRegions(true). SetScrollable(true). SetTitle("Result"). SetBorder(true) + rv.pages. + AddPage("result", rv.resultView, true, true). + AddPage("addPND", rv.pndInputView.GetContent(), true, false) + return rv } func (rv *ResultAndInputView) GetContent() tview.Primitive { - return rv.resultAndInputView + return rv.pages +} + +func (rv *ResultAndInputView) ChangeContentView(s string) { + rv.pages.SwitchToPage(s) } func (rv *ResultAndInputView) SetContent(s string) { - rv.resultAndInputView.Clear() - rv.resultAndInputView.SetText(s) + rv.resultView.Clear() + rv.resultView.SetText(s) } -- GitLab