diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-20 10:19:14 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-24 20:14:41 +1100 |
commit | cb26c7a1f20d754665e68db7abc8df3382cef66a (patch) | |
tree | a3707552a3732aaefe7588baf02fc4085fb98458 /pkg | |
parent | e392b9f86ab7683b231de4c1addd1986cffc9d91 (diff) |
more things
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/app/app.go | 28 | ||||
-rw-r--r-- | pkg/cheatsheet/generate.go | 9 | ||||
-rw-r--r-- | pkg/gui/information_panel.go | 23 |
3 files changed, 30 insertions, 30 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index 2d279936f..eeb1b849f 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/aybabtme/humanlog" + "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" @@ -284,13 +285,9 @@ func (app *App) Rebase() error { // Close closes any resources func (app *App) Close() error { - for _, closer := range app.closers { - err := closer.Close() - if err != nil { - return err - } - } - return nil + return slices.TryForEach(app.closers, func(closer io.Closer) error { + return closer.Close() + }) } // KnownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace @@ -299,10 +296,10 @@ func (app *App) KnownError(err error) (string, bool) { knownErrorMessages := []string{app.Tr.MinGitVersionError} - for _, message := range knownErrorMessages { - if errorMessage == message { - return message, true - } + if message, ok := slices.Find(knownErrorMessages, func(knownErrorMessage string) bool { + return knownErrorMessage == errorMessage + }); ok { + return message, true } mappings := []errorMapping{ @@ -312,11 +309,12 @@ func (app *App) KnownError(err error) (string, bool) { }, } - for _, mapping := range mappings { - if strings.Contains(errorMessage, mapping.originalError) { - return mapping.newError, true - } + if mapping, ok := slices.Find(mappings, func(mapping errorMapping) bool { + return strings.Contains(errorMessage, mapping.originalError) + }); ok { + return mapping.newError, true } + return "", false } diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index ecb75f935..04d8d3fd5 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -141,12 +141,11 @@ outer: if existing == nil { contextAndViewBindingMap[key] = []*types.Binding{binding} } else { - for _, navBinding := range contextAndViewBindingMap[key] { - if navBinding.Description == binding.Description { - continue outer - } + if !slices.Some(contextAndViewBindingMap[key], func(navBinding *types.Binding) bool { + return navBinding.Description == binding.Description + }) { + contextAndViewBindingMap[key] = append(contextAndViewBindingMap[key], binding) } - contextAndViewBindingMap[key] = append(contextAndViewBindingMap[key], binding) } continue outer diff --git a/pkg/gui/information_panel.go b/pkg/gui/information_panel.go index 3e317a349..4527da43b 100644 --- a/pkg/gui/information_panel.go +++ b/pkg/gui/information_panel.go @@ -3,15 +3,14 @@ package gui import ( "fmt" + "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/gui/style" ) func (gui *Gui) informationStr() string { - for _, mode := range gui.modeStatuses() { - if mode.isActive() { - return mode.description() - } + if activeMode, ok := gui.getActiveMode(); ok { + return activeMode.description() } if gui.g.Mouse { @@ -23,6 +22,12 @@ func (gui *Gui) informationStr() string { } } +func (gui *Gui) getActiveMode() (modeStatus, bool) { + return slices.Find(gui.modeStatuses(), func(mode modeStatus) bool { + return mode.isActive() + }) +} + func (gui *Gui) handleInfoClick() error { if !gui.g.Mouse { return nil @@ -33,13 +38,11 @@ func (gui *Gui) handleInfoClick() error { cx, _ := view.Cursor() width, _ := view.Size() - for _, mode := range gui.modeStatuses() { - if mode.isActive() { - if width-cx > len(gui.c.Tr.ResetInParentheses) { - return nil - } - return mode.reset() + if activeMode, ok := gui.getActiveMode(); ok { + if width-cx > len(gui.c.Tr.ResetInParentheses) { + return nil } + return activeMode.reset() } // if we're not in an active mode we show the donate button |