Skip to content
Snippets Groups Projects

V.0.1.0 Codename Threadbare

Closed Ghost User requested to merge v.0.1.0-codename-threadbare into master
3 files
+ 23
23
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 70
0
package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
commands "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc"
"github.com/rivo/tview"
"google.golang.org/grpc"
)
//CommandListView is an application view to display all the goSDN commands
type CommandListView struct {
title string
commandsList *tview.List
}
//NewCommandListView creates a new CommandListView
func NewCommandListView(title string) *CommandListView {
cv := &CommandListView{
title: title,
commandsList: tview.NewList(),
}
cv.commandsList.
SetBorder(true).
SetTitle(cv.title)
return cv
}
//GetContent returns the tview.Primitive belonging to the CommandListView
func (cv *CommandListView) GetContent() tview.Primitive {
return cv.commandsList
}
//GetTitle returns the title of the specific view
func (cv *CommandListView) GetTitle() string {
return cv.title
}
//GetCommands gets all goSDN commands from a command list and creates new
//tview.List items for each one of them. The specific gRPC functions are added
//as tview.Selected() function
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(rv.pndInputView.GetTitle())
app.SetFocus(rv.GetContent())
})
for i, command := range commands.CommandList {
f := command.Function
cv.commandsList.
AddItem(command.Name, command.Description, rune('b'+i), func() {
r := f(conn)
rv.SetContent(r)
rv.ChangeContentView(rv.GetTitle())
app.SetFocus(rv.GetContent())
})
}
cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() {
rv.ChangeContentView(rv.consoleLogView.GetTitle())
app.SetFocus(rv.GetContent())
})
cv.commandsList.AddItem("quit", "closes the application", 'q', func() {
app.Stop()
})
}
Loading