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

some clean up and changes for logView

parent e79254cc
Branches
Tags
3 merge requests!90Develop,!71Resolve "Stream logger-output to goSDN-tview via gRPC",!53V.0.1.0 Codename Threadbare
package app
import "github.com/rivo/tview"
import (
"github.com/rivo/tview"
)
type view interface {
GetContent() tview.Primitive
......@@ -17,6 +19,7 @@ func NewApp() *App {
a := &App{
app: tview.NewApplication(),
}
return a
}
......
......@@ -7,17 +7,19 @@ import (
//AddPNDView is an application view to create a new goSDN PND
type AddPNDView struct {
title string
addPNDView *tview.Form
}
//NewAddPNDView creates a new AddPNDView
func NewAddPNDView(app *app.App) *AddPNDView {
func NewAddPNDView(title string, app *app.App) *AddPNDView {
pndv := &AddPNDView{
title: title,
addPNDView: tview.NewForm(),
}
pndv.addPNDView.
SetBorder(true).
SetTitle("Add new PND")
SetTitle(pndv.title)
pndv.addPNDView.
AddInputField("Name", "", 20, nil, nil).
......@@ -40,3 +42,8 @@ func NewAddPNDView(app *app.App) *AddPNDView {
func (pndv *AddPNDView) GetContent() tview.Primitive {
return pndv.addPNDView
}
//GetTitle returns the title of the specific view
func (pndv *AddPNDView) GetTitle() string {
return pndv.title
}
......@@ -36,7 +36,7 @@ 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", 'a', func() {
rv.ChangeContentView("addPND")
rv.ChangeContentView(rv.pndInputView.GetTitle())
app.SetFocus(rv.GetContent())
})
......@@ -46,12 +46,14 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
AddItem(command.Name, command.Description, rune('b'+i), func() {
r := f(conn)
rv.SetContent(r)
rv.ChangeContentView("result")
rv.ChangeContentView(rv.GetTitle())
app.SetFocus(rv.GetContent())
})
}
cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() {
rv.ChangeContentView("log")
rv.ChangeContentView(rv.consoleLogView.GetTitle())
app.SetFocus(rv.GetContent())
})
cv.commandsList.AddItem("quit", "closes the application", 'q', func() {
......
......@@ -8,20 +8,23 @@ import (
//ConsoleLogView is an application view to create a view for goSDN log messages
type ConsoleLogView struct {
title string
consoleLogView *tview.TextView
}
//NewConsoleLogView creates a new ConsoleLogView
func NewConsoleLogView(conn *grpc.ClientConn) *ConsoleLogView {
func NewConsoleLogView(title string, conn *grpc.ClientConn) *ConsoleLogView {
clv := &ConsoleLogView{
consoleLogView: tview.NewTextView(),
title: title,
}
clv.consoleLogView.
SetDynamicColors(true).
SetTextAlign(tview.AlignCenter).
SetTextAlign(tview.AlignLeft).
SetScrollable(true).
SetRegions(true).
SetBorder(true).
SetTitle("goSDN Logs")
SetTitle(clv.title)
commands.GoSDNLogStream(conn, clv.consoleLogView)
......@@ -40,3 +43,8 @@ func (clv *ConsoleLogView) Write(s string) (n int, err error) {
b := []byte(s)
return clv.consoleLogView.Write(b)
}
//GetTitle returns the title of the specific view
func (clv *ConsoleLogView) GetTitle() string {
return clv.title
}
......@@ -21,13 +21,13 @@ type MainView struct {
//NewMainView creates a new MainView
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
mv := &MainView{
pages: tview.NewPages(),
mainGrid: tview.NewGrid(),
commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(app, conn),
headerView: NewHeaderView(),
footerView: NewFooterView(app, conn),
pages: tview.NewPages(),
mainGrid: tview.NewGrid(),
commandsListView: NewCommandListView(),
headerView: NewHeaderView(),
footerView: NewFooterView(app, conn),
}
mv.resultAndInputView = NewResultAndInputView("result and input", app, mv.commandsListView.GetContent(), conn)
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
mv.mainGrid.
......
......@@ -2,6 +2,7 @@ package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"google.golang.org/grpc"
)
......@@ -9,6 +10,7 @@ import (
//ResultAndInputView is an application view to display different other views.
//Depending on the required features the views are changed.
type ResultAndInputView struct {
title string
pages *tview.Pages
resultView *tview.TextView
pndInputView *AddPNDView
......@@ -16,24 +18,33 @@ type ResultAndInputView struct {
}
//NewResultAndInputView creates a new ResultAndInputView
func NewResultAndInputView(app *app.App, conn *grpc.ClientConn) *ResultAndInputView {
func NewResultAndInputView(title string, app *app.App, commandListView tview.Primitive, conn *grpc.ClientConn) *ResultAndInputView {
rv := &ResultAndInputView{
title: title,
pages: tview.NewPages(),
pndInputView: NewAddPNDView(app),
pndInputView: NewAddPNDView("add PND", app),
resultView: tview.NewTextView(),
consoleLogView: NewConsoleLogView(conn),
consoleLogView: NewConsoleLogView("logs", conn),
}
rv.resultView.
SetDynamicColors(true).
SetRegions(true).
SetScrollable(true).
SetTitle("Result").
SetTitle(rv.title).
SetBorder(true)
rv.pages.
AddPage("result", rv.resultView, true, true).
AddPage("addPND", rv.pndInputView.GetContent(), true, false).
AddPage("log", rv.consoleLogView.GetContent(), true, false)
AddPage(rv.title, rv.resultView, true, true).
AddPage(rv.pndInputView.GetTitle(), rv.pndInputView.GetContent(), true, false).
AddPage(rv.consoleLogView.GetTitle(), rv.consoleLogView.GetContent(), true, false)
rv.pages.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
k := event.Key()
if k == tcell.KeyESC {
app.SetFocus(commandListView)
}
return event
})
return rv
}
......@@ -54,3 +65,8 @@ func (rv *ResultAndInputView) SetContent(s string) {
rv.resultView.Clear()
rv.resultView.SetText(s)
}
//GetTitle returns the title of the specific view
func (rv *ResultAndInputView) GetTitle() string {
return rv.title
}
......@@ -5,6 +5,7 @@ go 1.14
require (
code.fbi.h-da.de/cocsn/swagger/apis v0.0.0-20200924152423-61030cab7b88
github.com/BurntSushi/toml v0.3.1
github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591
github.com/go-openapi/runtime v0.19.22
github.com/go-openapi/strfmt v0.19.5
github.com/golang/protobuf v1.4.2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment