2022-02-05 08:04:10 +02:00
|
|
|
package context
|
2021-04-11 05:17:20 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
type SimpleContext struct {
|
2022-01-16 05:46:53 +02:00
|
|
|
OnFocus func(opts ...types.OnFocusOpts) error
|
2021-11-21 03:48:49 +02:00
|
|
|
OnFocusLost func() error
|
|
|
|
OnRender func() error
|
|
|
|
// this is for pushing some content to the main view
|
2022-01-29 10:09:20 +02:00
|
|
|
OnRenderToMain func(opts ...types.OnFocusOpts) error
|
2021-04-11 05:17:20 +02:00
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
*BaseContext
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
type ContextCallbackOpts struct {
|
2022-01-29 10:09:20 +02:00
|
|
|
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
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
func NewSimpleContext(baseContext *BaseContext, opts ContextCallbackOpts) *SimpleContext {
|
2022-01-29 10:09:20 +02:00
|
|
|
return &SimpleContext{
|
|
|
|
OnFocus: opts.OnFocus,
|
|
|
|
OnFocusLost: opts.OnFocusLost,
|
|
|
|
OnRender: opts.OnRender,
|
|
|
|
OnRenderToMain: opts.OnRenderToMain,
|
|
|
|
BaseContext: baseContext,
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
var _ types.Context = &SimpleContext{}
|
|
|
|
|
|
|
|
func (self *SimpleContext) HandleFocus(opts ...types.OnFocusOpts) error {
|
2021-11-21 03:48:49 +02:00
|
|
|
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
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
func (self *SimpleContext) HandleFocusLost() error {
|
2021-11-21 03:48:49 +02:00
|
|
|
if self.OnFocusLost != nil {
|
|
|
|
return self.OnFocusLost()
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
func (self *SimpleContext) HandleRender() error {
|
|
|
|
if self.OnRender != nil {
|
|
|
|
return self.OnRender()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
func (self *SimpleContext) HandleRenderToMain() error {
|
2021-11-21 03:48:49 +02:00
|
|
|
if self.OnRenderToMain != nil {
|
|
|
|
return self.OnRenderToMain()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|