diff options
Diffstat (limited to 'pkg/gui/context/simple_context.go')
-rw-r--r-- | pkg/gui/context/simple_context.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/pkg/gui/context/simple_context.go b/pkg/gui/context/simple_context.go index ae201295b..835576264 100644 --- a/pkg/gui/context/simple_context.go +++ b/pkg/gui/context/simple_context.go @@ -1,25 +1,25 @@ package context import ( + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type SimpleContext struct { - OnFocus func(opts ...types.OnFocusOpts) error - OnFocusLost func() error + OnFocus func(opts types.OnFocusOpts) error + OnFocusLost func(opts types.OnFocusLostOpts) error OnRender func() error // this is for pushing some content to the main view - OnRenderToMain func(opts ...types.OnFocusOpts) error + OnRenderToMain func() error *BaseContext } type ContextCallbackOpts 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 + OnFocus func(opts types.OnFocusOpts) error + OnFocusLost func(opts types.OnFocusLostOpts) error + OnRender func() error + OnRenderToMain func() error } func NewSimpleContext(baseContext *BaseContext, opts ContextCallbackOpts) *SimpleContext { @@ -34,15 +34,30 @@ func NewSimpleContext(baseContext *BaseContext, opts ContextCallbackOpts) *Simpl var _ types.Context = &SimpleContext{} -func (self *SimpleContext) HandleFocus(opts ...types.OnFocusOpts) error { +// A Display context only renders a view. It has no keybindings and is not focusable. +func NewDisplayContext(key types.ContextKey, view *gocui.View, windowName string) types.Context { + return NewSimpleContext( + NewBaseContext(NewBaseContextOpts{ + Kind: types.DISPLAY_CONTEXT, + Key: key, + View: view, + WindowName: windowName, + Focusable: false, + Transient: false, + }), + ContextCallbackOpts{}, + ) +} + +func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) error { if self.OnFocus != nil { - if err := self.OnFocus(opts...); err != nil { + if err := self.OnFocus(opts); err != nil { return err } } if self.OnRenderToMain != nil { - if err := self.OnRenderToMain(opts...); err != nil { + if err := self.OnRenderToMain(); err != nil { return err } } @@ -50,9 +65,9 @@ func (self *SimpleContext) HandleFocus(opts ...types.OnFocusOpts) error { return nil } -func (self *SimpleContext) HandleFocusLost() error { +func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error { if self.OnFocusLost != nil { - return self.OnFocusLost() + return self.OnFocusLost(opts) } return nil } |