From b4d097639560b60ebf95ca6d2a3b10f89692b871 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Wed, 21 Oct 2020 13:03:34 +0200 Subject: [PATCH] added view for goSDN logs --- cmd/gosdn-tview/views/commandsListView.go | 8 +++-- cmd/gosdn-tview/views/consoleLogView.go | 36 +++++++++++++++++++++ cmd/gosdn-tview/views/resultAndInputView.go | 17 ++++++---- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 cmd/gosdn-tview/views/consoleLogView.go diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 8c7488daa..23ad1c8c8 100644 --- a/cmd/gosdn-tview/views/commandsListView.go +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive { 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() { + cv.commandsList.AddItem("AddPND", "closes the application", 'a', func() { rv.ChangeContentView("addPND") app.SetFocus(rv.GetContent()) }) @@ -43,13 +43,17 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, for i, command := range commands.CommandList { f := command.Function cv.commandsList. - AddItem(command.Name, command.Description, rune('a'+i), func() { + AddItem(command.Name, command.Description, rune('b'+i), func() { r := f(conn) rv.SetContent(r) rv.ChangeContentView("result") }) } + cv.commandsList.AddItem("Show Log", "shows the log of goSDN", 'l', func() { + rv.ChangeContentView("log") + }) + cv.commandsList.AddItem("quit", "closes the application", 'q', func() { app.Stop() }) diff --git a/cmd/gosdn-tview/views/consoleLogView.go b/cmd/gosdn-tview/views/consoleLogView.go new file mode 100644 index 000000000..5a487fecf --- /dev/null +++ b/cmd/gosdn-tview/views/consoleLogView.go @@ -0,0 +1,36 @@ +package views + +import "github.com/rivo/tview" + +//ConsoleLogView is an application view to create a view for goSDN log messages +type ConsoleLogView struct { + consoleLogView *tview.TextView +} + +//NewConsoleLogView creates a new ConsoleLogView +func NewConsoleLogView() *ConsoleLogView { + clv := &ConsoleLogView{ + consoleLogView: tview.NewTextView(), + } + clv.consoleLogView. + SetDynamicColors(true). + SetTextAlign(tview.AlignCenter). + SetRegions(true). + SetBorder(true). + SetTitle("goSDN Logger Output") + + return clv +} + +//GetContent returns the tview.Primitive belonging to the ConsoleLogView +func (clv *ConsoleLogView) GetContent() tview.Primitive { + return clv.consoleLogView +} + +//Write implements the io.Writer interface via tview.textView.Write(). +//Gets a string and converts it to a byte slice and writes it to the textView +//buffer +func (clv *ConsoleLogView) Write(s string) (n int, err error) { + b := []byte(s) + return clv.consoleLogView.Write(b) +} diff --git a/cmd/gosdn-tview/views/resultAndInputView.go b/cmd/gosdn-tview/views/resultAndInputView.go index ec74e2e49..23f2004b7 100644 --- a/cmd/gosdn-tview/views/resultAndInputView.go +++ b/cmd/gosdn-tview/views/resultAndInputView.go @@ -8,17 +8,19 @@ import ( //ResultAndInputView is an application view to display different other views. //Depending on the required features the views are changed. type ResultAndInputView struct { - pages *tview.Pages - resultView *tview.TextView - pndInputView *AddPNDView + pages *tview.Pages + resultView *tview.TextView + pndInputView *AddPNDView + consoleLogView *ConsoleLogView } //NewResultAndInputView creates a new ResultAndInputView func NewResultAndInputView(app *app.App) *ResultAndInputView { rv := &ResultAndInputView{ - pages: tview.NewPages(), - pndInputView: NewAddPNDView(app), - resultView: tview.NewTextView(), + pages: tview.NewPages(), + pndInputView: NewAddPNDView(app), + resultView: tview.NewTextView(), + consoleLogView: NewConsoleLogView(), } rv.resultView. SetDynamicColors(true). @@ -29,7 +31,8 @@ func NewResultAndInputView(app *app.App) *ResultAndInputView { rv.pages. AddPage("result", rv.resultView, true, true). - AddPage("addPND", rv.pndInputView.GetContent(), true, false) + AddPage("addPND", rv.pndInputView.GetContent(), true, false). + AddPage("log", rv.consoleLogView.GetContent(), true, false) return rv } -- GitLab