Skip to content
Snippets Groups Projects
commandsListView.go 1.12 KiB
Newer Older
  • Learn to ignore specific revisions
  • package views
    
    import (
    
    Malte Bauch's avatar
    Malte Bauch committed
    	"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"
    
    Malte Bauch's avatar
    Malte Bauch committed
    	"google.golang.org/grpc"
    
    )
    
    type CommandListView struct {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	commandsList *tview.List
    
    Malte Bauch's avatar
    Malte Bauch committed
    func NewCommandListView() *CommandListView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	cv := &CommandListView{
    
    Malte Bauch's avatar
    Malte Bauch committed
    		commandsList: tview.NewList(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    	}
    
    Malte Bauch's avatar
    Malte Bauch committed
    	cv.commandsList.
    
    		SetBorder(true).
    
    Malte Bauch's avatar
    Malte Bauch committed
    		SetTitle("Commands")
    
    Malte Bauch's avatar
    Malte Bauch committed
    	return cv
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (cv *CommandListView) GetContent() tview.Primitive {
    	return cv.commandsList
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
    
    	conn *grpc.ClientConn) {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	//TODO: create own command in grpc -> commands
    	cv.commandsList.AddItem("AddPND", "closes the application", '!', func() {
    
    		rv.ChangeContentView("addPND")
    		app.SetFocus(rv.GetContent())
    
    Malte Bauch's avatar
    Malte Bauch committed
    	})
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    	for i, command := range commands.CommandList {
    		f := command.Function
    
    Malte Bauch's avatar
    Malte Bauch committed
    		cv.commandsList.
    
    Malte Bauch's avatar
    Malte Bauch committed
    			AddItem(command.Name, command.Description, rune('a'+i), func() {
    
    				r := f(conn)
    				rv.SetContent(r)
    
    				rv.ChangeContentView("result")
    
    Malte Bauch's avatar
    Malte Bauch committed
    	cv.commandsList.AddItem("quit", "closes the application", 'q', func() {
    
    Malte Bauch's avatar
    Malte Bauch committed
    		app.Stop()
    	})