diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 8c7488daafacd1ca3942056f91bc8c1cfefb42b2..23ad1c8c880d71029f552712978a33107ae095da 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 0000000000000000000000000000000000000000..5a487fecf5dee9115f4ae0c775a14bb079e4027e --- /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 ec74e2e4929b3e7e7bc902f7eb219b97bed5f4ef..23f2004b74eee9bc3f219c0db0ab6c372c203b66 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 }