1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/context/simple_context.go

72 lines
1.4 KiB
Go
Raw Normal View History

2022-02-05 08:04:10 +02:00
package context
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
2022-01-29 10:09:20 +02:00
type SimpleContext struct {
2022-02-05 08:04:10 +02:00
*BaseContext
}
2023-03-21 12:01:58 +02:00
func NewSimpleContext(baseContext *BaseContext) *SimpleContext {
2022-01-29 10:09:20 +02:00
return &SimpleContext{
BaseContext: baseContext,
}
}
2022-01-29 10:09:20 +02:00
var _ types.Context = &SimpleContext{}
// 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,
}),
)
}
func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) error {
if self.highlightOnFocus {
self.GetViewTrait().SetHighlight(true)
}
if self.onFocusFn != nil {
if err := self.onFocusFn(opts); err != nil {
return err
}
}
if self.onRenderToMainFn != nil {
if err := self.onRenderToMainFn(); err != nil {
return err
}
}
return nil
}
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error {
if self.onFocusLostFn != nil {
return self.onFocusLostFn(opts)
}
return nil
}
2022-02-05 08:04:10 +02:00
func (self *SimpleContext) HandleRender() error {
return nil
}
2022-01-29 10:09:20 +02:00
func (self *SimpleContext) HandleRenderToMain() error {
if self.onRenderToMainFn != nil {
return self.onRenderToMainFn()
}
return nil
}