1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-03 15:02:52 +02:00
lazygit/pkg/gui/controllers/helpers/view_helper.go

34 lines
675 B
Go
Raw Normal View History

package helpers
import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type ViewHelper struct {
c *HelperCommon
contexts *context.ContextTree
}
func NewViewHelper(c *HelperCommon, contexts *context.ContextTree) *ViewHelper {
return &ViewHelper{
c: c,
contexts: contexts,
}
}
func (self *ViewHelper) ContextForView(viewName string) (types.Context, bool) {
view, err := self.c.GocuiGui().View(viewName)
if err != nil {
return nil, false
}
for _, context := range self.contexts.Flatten() {
if context.GetViewName() == view.Name() {
return context, true
}
}
return nil, false
}