summaryrefslogtreecommitdiffstats
path: root/pkg/gui/simple_context.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/simple_context.go')
-rw-r--r--pkg/gui/simple_context.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/pkg/gui/simple_context.go b/pkg/gui/simple_context.go
new file mode 100644
index 000000000..e9a3ca933
--- /dev/null
+++ b/pkg/gui/simple_context.go
@@ -0,0 +1,74 @@
+package gui
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
+)
+
+type SimpleContext struct {
+ OnFocus func(opts ...types.OnFocusOpts) error
+ OnFocusLost func() error
+ OnRender func() error
+ // this is for pushing some content to the main view
+ OnRenderToMain func(opts ...types.OnFocusOpts) error
+
+ *context.BaseContext
+}
+
+type NewSimpleContextOpts struct {
+ OnFocus func(opts ...types.OnFocusOpts) error
+ OnFocusLost func() error
+ OnRender func() error
+ // this is for pushing some content to the main view
+ OnRenderToMain func(opts ...types.OnFocusOpts) error
+}
+
+func NewSimpleContext(baseContext *context.BaseContext, opts NewSimpleContextOpts) *SimpleContext {
+ return &SimpleContext{
+ OnFocus: opts.OnFocus,
+ OnFocusLost: opts.OnFocusLost,
+ OnRender: opts.OnRender,
+ OnRenderToMain: opts.OnRenderToMain,
+ BaseContext: baseContext,
+ }
+}
+
+var _ types.Context = &SimpleContext{}
+
+func (self *SimpleContext) HandleRender() error {
+ if self.OnRender != nil {
+ return self.OnRender()
+ }
+ return nil
+}
+
+func (self *SimpleContext) HandleFocus(opts ...types.OnFocusOpts) error {
+ if self.OnFocus != nil {
+ if err := self.OnFocus(opts...); err != nil {
+ return err
+ }
+ }
+
+ if self.OnRenderToMain != nil {
+ if err := self.OnRenderToMain(opts...); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (self *SimpleContext) HandleFocusLost() error {
+ if self.OnFocusLost != nil {
+ return self.OnFocusLost()
+ }
+ return nil
+}
+
+func (self *SimpleContext) HandleRenderToMain() error {
+ if self.OnRenderToMain != nil {
+ return self.OnRenderToMain()
+ }
+
+ return nil
+}