summaryrefslogtreecommitdiffstats
path: root/ui/status_controller.go
blob: c204e9ecf66cfb7dc66c21a3fe0209bea619d7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package ui

import (
	"fmt"

	"strings"

	"github.com/jroimartin/gocui"
)

// StatusController holds the UI objects and data models for populating the bottom-most pane. Specifically the panel
// shows the user a set of possible actions to take in the window and currently selected pane.
type StatusController struct {
	Name string
	gui  *gocui.Gui
	view *gocui.View
}

// NewStatusController creates a new view object attached the the global [gocui] screen object.
func NewStatusController(name string, gui *gocui.Gui) (controller *StatusController) {
	controller = new(StatusController)

	// populate main fields
	controller.Name = name
	controller.gui = gui

	return controller
}

// Setup initializes the UI concerns within the context of a global [gocui] view object.
func (controller *StatusController) Setup(v *gocui.View, header *gocui.View) error {

	// set controller options
	controller.view = v
	controller.view.Frame = false

	controller.Render()

	return nil
}

// IsVisible indicates if the status view pane is currently initialized.
func (controller *StatusController) IsVisible() bool {
	if controller == nil {
		return false
	}
	return true
}

// CursorDown moves the cursor down in the details pane (currently indicates nothing).
func (controller *StatusController) CursorDown() error {
	return nil
}

// CursorUp moves the cursor up in the details pane (currently indicates nothing).
func (controller *StatusController) CursorUp() error {
	return nil
}

// Update refreshes the state objects for future rendering (currently does nothing).
func (controller *StatusController) Update() error {
	return nil
}

// Render flushes the state objects to the screen.
func (controller *StatusController) Render() error {
	controller.gui.Update(func(g *gocui.Gui) error {
		controller.view.Clear()
		fmt.Fprintln(controller.view, controller.KeyHelp()+Controllers.lookup[controller.gui.CurrentView().Name()].KeyHelp()+Formatting.StatusNormal("▏"+strings.Repeat(" ", 1000)))

		return nil
	})
	// todo: blerg
	return nil
}

// KeyHelp indicates all the possible global actions a user can take when any pane is selected.
func (controller *StatusController) KeyHelp() string {
	return renderStatusOption(GlobalKeybindings.quit[0].String(), "Quit", false) +
		renderStatusOption(GlobalKeybindings.toggleView[0].String(), "Switch view", false) +
		renderStatusOption(GlobalKeybindings.filterView[0].String(), "Filter", Controllers.Filter.IsVisible())
}