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

added view for goSDN logs

parent 58362917
No related branches found
No related tags found
3 merge requests!90Develop,!69Resolve "Stream logger-output to goSDN-tview via gRPC",!53V.0.1.0 Codename Threadbare
...@@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive { ...@@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive {
func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) { conn *grpc.ClientConn) {
//TODO: create own command in grpc -> commands //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") rv.ChangeContentView("addPND")
app.SetFocus(rv.GetContent()) app.SetFocus(rv.GetContent())
}) })
...@@ -43,13 +43,17 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, ...@@ -43,13 +43,17 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
for i, command := range commands.CommandList { for i, command := range commands.CommandList {
f := command.Function f := command.Function
cv.commandsList. cv.commandsList.
AddItem(command.Name, command.Description, rune('a'+i), func() { AddItem(command.Name, command.Description, rune('b'+i), func() {
r := f(conn) r := f(conn)
rv.SetContent(r) rv.SetContent(r)
rv.ChangeContentView("result") 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() { cv.commandsList.AddItem("quit", "closes the application", 'q', func() {
app.Stop() app.Stop()
}) })
......
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)
}
...@@ -8,17 +8,19 @@ import ( ...@@ -8,17 +8,19 @@ import (
//ResultAndInputView is an application view to display different other views. //ResultAndInputView is an application view to display different other views.
//Depending on the required features the views are changed. //Depending on the required features the views are changed.
type ResultAndInputView struct { type ResultAndInputView struct {
pages *tview.Pages pages *tview.Pages
resultView *tview.TextView resultView *tview.TextView
pndInputView *AddPNDView pndInputView *AddPNDView
consoleLogView *ConsoleLogView
} }
//NewResultAndInputView creates a new ResultAndInputView //NewResultAndInputView creates a new ResultAndInputView
func NewResultAndInputView(app *app.App) *ResultAndInputView { func NewResultAndInputView(app *app.App) *ResultAndInputView {
rv := &ResultAndInputView{ rv := &ResultAndInputView{
pages: tview.NewPages(), pages: tview.NewPages(),
pndInputView: NewAddPNDView(app), pndInputView: NewAddPNDView(app),
resultView: tview.NewTextView(), resultView: tview.NewTextView(),
consoleLogView: NewConsoleLogView(),
} }
rv.resultView. rv.resultView.
SetDynamicColors(true). SetDynamicColors(true).
...@@ -29,7 +31,8 @@ func NewResultAndInputView(app *app.App) *ResultAndInputView { ...@@ -29,7 +31,8 @@ func NewResultAndInputView(app *app.App) *ResultAndInputView {
rv.pages. rv.pages.
AddPage("result", rv.resultView, true, true). 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 return rv
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment