summaryrefslogtreecommitdiffstats
path: root/pkg/gui/basic_context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-11 13:17:20 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-11 17:07:49 +1000
commitcf78b86cb5eae4c502a747238aba983bf9eb298f (patch)
treec81eb86f8a291b7b91046e754f5ddfef77afff43 /pkg/gui/basic_context.go
parent4f03d7733ab186d357064f343915ac48ca059940 (diff)
more support for command log and more code reuse for contexts
Diffstat (limited to 'pkg/gui/basic_context.go')
-rw-r--r--pkg/gui/basic_context.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/pkg/gui/basic_context.go b/pkg/gui/basic_context.go
new file mode 100644
index 000000000..78cf85144
--- /dev/null
+++ b/pkg/gui/basic_context.go
@@ -0,0 +1,77 @@
+package gui
+
+type BasicContext struct {
+ OnFocus func() error
+ OnFocusLost func() error
+ OnRender func() error
+ Kind ContextKind
+ Key ContextKey
+ ViewName string
+ WindowName string
+ OnGetOptionsMap func() map[string]string
+
+ ParentContext Context
+ // we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this
+ hasParent bool
+}
+
+func (c *BasicContext) GetOptionsMap() map[string]string {
+ if c.OnGetOptionsMap != nil {
+ return c.OnGetOptionsMap()
+ }
+ return nil
+}
+
+func (c *BasicContext) SetParentContext(context Context) {
+ c.ParentContext = context
+ c.hasParent = true
+}
+
+func (c *BasicContext) GetParentContext() (Context, bool) {
+ return c.ParentContext, c.hasParent
+}
+
+func (c *BasicContext) SetWindowName(windowName string) {
+ c.WindowName = windowName
+}
+
+func (c *BasicContext) GetWindowName() string {
+ windowName := c.WindowName
+
+ if windowName != "" {
+ return windowName
+ }
+
+ // TODO: actually set this for everything so we don't default to the view name
+ return c.ViewName
+}
+
+func (c *BasicContext) HandleRender() error {
+ if c.OnRender != nil {
+ return c.OnRender()
+ }
+ return nil
+}
+
+func (c *BasicContext) GetViewName() string {
+ return c.ViewName
+}
+
+func (c *BasicContext) HandleFocus() error {
+ return c.OnFocus()
+}
+
+func (c *BasicContext) HandleFocusLost() error {
+ if c.OnFocusLost != nil {
+ return c.OnFocusLost()
+ }
+ return nil
+}
+
+func (c *BasicContext) GetKind() ContextKind {
+ return c.Kind
+}
+
+func (c *BasicContext) GetKey() ContextKey {
+ return c.Key
+}