1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

start moving getDisplayStrings funcs into contexts

This commit is contained in:
Jesse Duffield 2023-03-21 21:38:37 +11:00
parent 0e5a4c7a36
commit 1b2fb34ffd
7 changed files with 52 additions and 46 deletions

View File

@ -100,7 +100,7 @@ func (self *WindowArranger) mainSectionChildren() []*boxlayout.Box {
// if we're not in split mode we can just show the one main panel. Likewise if
// the main panel is focused and we're in full-screen mode
if !self.gui.isMainPanelSplit() || (self.gui.State.ScreenMode == SCREEN_FULL && currentWindow == "main") {
if !self.gui.isMainPanelSplit() || (self.gui.State.ScreenMode == types.SCREEN_FULL && currentWindow == "main") {
return []*boxlayout.Box{
{
Window: "main",
@ -135,13 +135,13 @@ func (self *WindowArranger) getMidSectionWeights() (int, int) {
}
if currentWindow == "main" {
if self.gui.State.ScreenMode == SCREEN_HALF || self.gui.State.ScreenMode == SCREEN_FULL {
if self.gui.State.ScreenMode == types.SCREEN_HALF || self.gui.State.ScreenMode == types.SCREEN_FULL {
sideSectionWeight = 0
}
} else {
if self.gui.State.ScreenMode == SCREEN_HALF {
if self.gui.State.ScreenMode == types.SCREEN_HALF {
mainSectionWeight = 1
} else if self.gui.State.ScreenMode == SCREEN_FULL {
} else if self.gui.State.ScreenMode == types.SCREEN_FULL {
mainSectionWeight = 0
}
}
@ -255,7 +255,7 @@ func (self *WindowArranger) getDefaultStashWindowBox() *boxlayout.Box {
func (self *WindowArranger) sidePanelChildren(width int, height int) []*boxlayout.Box {
currentWindow := self.currentSideWindowName()
if self.gui.State.ScreenMode == SCREEN_FULL || self.gui.State.ScreenMode == SCREEN_HALF {
if self.gui.State.ScreenMode == types.SCREEN_FULL || self.gui.State.ScreenMode == types.SCREEN_HALF {
fullHeightBox := func(window string) *boxlayout.Box {
if window == currentWindow {
return &boxlayout.Box{

View File

@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -15,13 +16,18 @@ var (
_ types.DiffableContext = (*BranchesContext)(nil)
)
func NewBranchesContext(
getDisplayStrings func(startIdx int, length int) [][]string,
c *types.HelperCommon,
) *BranchesContext {
func NewBranchesContext(c *types.HelperCommon) *BranchesContext {
viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches })
getDisplayStrings := func(startIdx int, length int) [][]string {
return presentation.GetBranchListDisplayStrings(
c.Model().Branches,
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().Diffing.Ref,
c.Tr,
)
}
self := &BranchesContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{

View File

@ -23,8 +23,8 @@ func (gui *Gui) exitFilterMode() error {
func (gui *Gui) clearFiltering() error {
gui.State.Modes.Filtering.Reset()
if gui.State.ScreenMode == SCREEN_HALF {
gui.State.ScreenMode = SCREEN_NORMAL
if gui.State.ScreenMode == types.SCREEN_HALF {
gui.State.ScreenMode = types.SCREEN_NORMAL
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
@ -32,8 +32,8 @@ func (gui *Gui) clearFiltering() error {
func (gui *Gui) setFiltering(path string) error {
gui.State.Modes.Filtering.SetPath(path)
if gui.State.ScreenMode == SCREEN_NORMAL {
gui.State.ScreenMode = SCREEN_HALF
if gui.State.ScreenMode == types.SCREEN_NORMAL {
gui.State.ScreenMode = types.SCREEN_HALF
}
if err := gui.c.PushContext(gui.State.Contexts.LocalCommits); err != nil {

View File

@ -24,7 +24,7 @@ func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error {
return nil
}
func nextIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowMaximisation {
func nextIntInCycle(sl []types.WindowMaximisation, current types.WindowMaximisation) types.WindowMaximisation {
for i, val := range sl {
if val == current {
if i == len(sl)-1 {
@ -36,7 +36,7 @@ func nextIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowM
return sl[0]
}
func prevIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowMaximisation {
func prevIntInCycle(sl []types.WindowMaximisation, current types.WindowMaximisation) types.WindowMaximisation {
for i, val := range sl {
if val == current {
if i > 0 {
@ -49,13 +49,13 @@ func prevIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowM
}
func (gui *Gui) nextScreenMode() error {
gui.State.ScreenMode = nextIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode)
gui.State.ScreenMode = nextIntInCycle([]types.WindowMaximisation{types.SCREEN_NORMAL, types.SCREEN_HALF, types.SCREEN_FULL}, gui.State.ScreenMode)
return gui.rerenderViewsWithScreenModeDependentContent()
}
func (gui *Gui) prevScreenMode() error {
gui.State.ScreenMode = prevIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode)
gui.State.ScreenMode = prevIntInCycle([]types.WindowMaximisation{types.SCREEN_NORMAL, types.SCREEN_HALF, types.SCREEN_FULL}, gui.State.ScreenMode)
return gui.rerenderViewsWithScreenModeDependentContent()
}

View File

@ -42,18 +42,6 @@ import (
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
)
// screen sizing determines how much space your selected window takes up (window
// as in panel, not your terminal's window). Sometimes you want a bit more space
// to see the contents of a panel, and this keeps track of how much maximisation
// you've set
type WindowMaximisation int
const (
SCREEN_NORMAL WindowMaximisation = iota
SCREEN_HALF
SCREEN_FULL
)
const StartupPopupVersion = 5
// OverlappingEdges determines if panel edges overlap
@ -216,7 +204,7 @@ type GuiRepoState struct {
// panel without committing or if our commit failed
savedCommitMessage string
ScreenMode WindowMaximisation
ScreenMode types.WindowMaximisation
CurrentPopupOpts *types.CreatePopupPanelOpts
}
@ -247,6 +235,10 @@ func (self *GuiRepoState) SetCurrentPopupOpts(value *types.CreatePopupPanelOpts)
self.CurrentPopupOpts = value
}
func (self *GuiRepoState) GetScreenMode() types.WindowMaximisation {
return self.ScreenMode
}
type searchingState struct {
view *gocui.View
isSearching bool
@ -353,19 +345,19 @@ func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSaf
return result
}
func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) WindowMaximisation {
func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) types.WindowMaximisation {
if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
return SCREEN_HALF
return types.SCREEN_HALF
} else {
defaultWindowSize := config.GetUserConfig().Gui.WindowSize
switch defaultWindowSize {
case "half":
return SCREEN_HALF
return types.SCREEN_HALF
case "full":
return SCREEN_FULL
return types.SCREEN_FULL
default:
return SCREEN_NORMAL
return types.SCREEN_NORMAL
}
}
}

View File

@ -21,12 +21,7 @@ func (gui *Gui) filesListContext() *context.WorkingTreeContext {
}
func (gui *Gui) branchesListContext() *context.BranchesContext {
return context.NewBranchesContext(
func(startIdx int, length int) [][]string {
return presentation.GetBranchListDisplayStrings(gui.State.Model.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref, gui.Tr)
},
gui.c,
)
return context.NewBranchesContext(gui.c)
}
func (gui *Gui) remotesListContext() *context.RemotesContext {
@ -82,7 +77,7 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
return presentation.GetCommitListDisplayStrings(
gui.Common,
gui.State.Model.Commits,
gui.State.ScreenMode != SCREEN_NORMAL,
gui.State.ScreenMode != types.SCREEN_NORMAL,
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Gui.TimeFormat,
@ -112,7 +107,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
return presentation.GetCommitListDisplayStrings(
gui.Common,
gui.State.Model.SubCommits,
gui.State.ScreenMode != SCREEN_NORMAL,
gui.State.ScreenMode != types.SCREEN_NORMAL,
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Gui.TimeFormat,
@ -141,7 +136,7 @@ func (gui *Gui) shouldShowGraph() bool {
case "never":
return false
case "when-maximised":
return gui.State.ScreenMode != SCREEN_NORMAL
return gui.State.ScreenMode != types.SCREEN_NORMAL
}
log.Fatalf("Unknown value for git.log.showGraph: %s. Expected one of: 'always', 'never', 'when-maximised'", value)
@ -153,7 +148,7 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
func(startIdx int, length int) [][]string {
return presentation.GetReflogCommitListDisplayStrings(
gui.State.Model.FilteredReflogCommits,
gui.State.ScreenMode != SCREEN_NORMAL,
gui.State.ScreenMode != types.SCREEN_NORMAL,
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Gui.TimeFormat,

View File

@ -225,6 +225,7 @@ type IRepoStateAccessor interface {
SetStartupStage(stage StartupStage)
GetCurrentPopupOpts() *CreatePopupPanelOpts
SetCurrentPopupOpts(*CreatePopupPanelOpts)
GetScreenMode() WindowMaximisation
}
// startup stages so we don't need to load everything at once
@ -238,3 +239,15 @@ const (
type IFileWatcher interface {
AddFilesToFileWatcher(files []*models.File) error
}
// screen sizing determines how much space your selected window takes up (window
// as in panel, not your terminal's window). Sometimes you want a bit more space
// to see the contents of a panel, and this keeps track of how much maximisation
// you've set
type WindowMaximisation int
const (
SCREEN_NORMAL WindowMaximisation = iota
SCREEN_HALF
SCREEN_FULL
)