1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00
lazygit/pkg/gui/context/base_context.go
2022-03-17 19:13:40 +11:00

68 lines
1.4 KiB
Go

package context
import "github.com/jesseduffield/lazygit/pkg/gui/types"
type BaseContext struct {
Kind types.ContextKind
Key types.ContextKey
ViewName string
WindowName string
OnGetOptionsMap func() map[string]string
*ParentContextMgr
}
func (self *BaseContext) GetOptionsMap() map[string]string {
if self.OnGetOptionsMap != nil {
return self.OnGetOptionsMap()
}
return nil
}
func (self *BaseContext) SetWindowName(windowName string) {
self.WindowName = windowName
}
func (self *BaseContext) GetWindowName() string {
windowName := self.WindowName
if windowName != "" {
return windowName
}
// TODO: actually set this for everything so we don't default to the view name
return self.ViewName
}
func (self *BaseContext) GetViewName() string {
return self.ViewName
}
func (self *BaseContext) GetKind() types.ContextKind {
return self.Kind
}
func (self *BaseContext) GetKey() types.ContextKey {
return self.Key
}
type NewBaseContextOpts struct {
Kind types.ContextKind
Key types.ContextKey
ViewName string
WindowName string
OnGetOptionsMap func() map[string]string
}
func NewBaseContext(opts NewBaseContextOpts) *BaseContext {
return &BaseContext{
Kind: opts.Kind,
Key: opts.Key,
ViewName: opts.ViewName,
WindowName: opts.WindowName,
OnGetOptionsMap: opts.OnGetOptionsMap,
ParentContextMgr: &ParentContextMgr{},
}
}