diff --git a/cmd/gosdn-tview/main.go b/cmd/gosdn-tview/main.go index ef8c54ef9c799e70f0471414f67bcc0f339ec22f..7f7368547959d5f92ebb922528b79d4214a2420b 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 0060852eeb51293b9a76b5784680a6b726cdb9b3..7fdf756110624cfc519a5be7596981c828e8a28c 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 16ff032ba64f44947ebccd07134ab5f82e59597d..2ab3f9452f436669a7f75c536a9775f68b29590a 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 e69d74dc6800d43a67a2989b3d6100224e7dccb5..6c95c811cc408ee1f5e5fa480ba33e573d044555 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 2e0e5f1af5606e11e2db79384cdf79aefd902bfd..99ae89654349c6347281c34c7b2149a6e4c64463 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) }