Skip to content
Snippets Groups Projects
commandsListView.go 979 B
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/gdamore/tcell"
    	"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
    	v := &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
    	v.commandsList.
    
    		SetBorder(true).
    
    Malte Bauch's avatar
    Malte Bauch committed
    		SetBorderColor(tcell.ColorSteelBlue).
    		SetTitle("Commands")
    
    
    	return v
    }
    
    func (c *CommandListView) GetContent() tview.Primitive {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	return c.commandsList
    
    func (v *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
    	conn *grpc.ClientConn) {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	for i, command := range commands.CommandList {
    		f := command.Function
    		v.commandsList.
    			AddItem(command.Name, command.Description, rune('a'+i), func() {
    
    				r := f(conn)
    				rv.SetContent(r)
    
    Malte Bauch's avatar
    Malte Bauch committed
    	v.commandsList.AddItem("quit", "closes the application", 'q', func() {
    		app.Stop()
    	})