Skip to content

Commit

Permalink
Color view frame differently when searching/filtering
Browse files Browse the repository at this point in the history
Given that we now persist search/filter states even after a side context loses focus, we need to make it really
clear to the user that the context is currently being searched/filtered
  • Loading branch information
jesseduffield committed Jul 3, 2023
1 parent 3ca1292 commit 9df634f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
3 changes: 3 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ gui:
- bold
inactiveBorderColor:
- white
searchingActiveBorderColor:
- cyan
- bold
optionsTextColor:
- blue
selectedLineBgColor:
Expand Down
38 changes: 20 additions & 18 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ type GuiConfig struct {
}

type ThemeConfig struct {
ActiveBorderColor []string `yaml:"activeBorderColor"`
InactiveBorderColor []string `yaml:"inactiveBorderColor"`
OptionsTextColor []string `yaml:"optionsTextColor"`
SelectedLineBgColor []string `yaml:"selectedLineBgColor"`
SelectedRangeBgColor []string `yaml:"selectedRangeBgColor"`
CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor"`
CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor"`
UnstagedChangesColor []string `yaml:"unstagedChangesColor"`
DefaultFgColor []string `yaml:"defaultFgColor"`
ActiveBorderColor []string `yaml:"activeBorderColor"`
InactiveBorderColor []string `yaml:"inactiveBorderColor"`
SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor"`
OptionsTextColor []string `yaml:"optionsTextColor"`
SelectedLineBgColor []string `yaml:"selectedLineBgColor"`
SelectedRangeBgColor []string `yaml:"selectedRangeBgColor"`
CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor"`
CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor"`
UnstagedChangesColor []string `yaml:"unstagedChangesColor"`
DefaultFgColor []string `yaml:"defaultFgColor"`
}

type CommitLengthConfig struct {
Expand Down Expand Up @@ -409,15 +410,16 @@ func GetDefaultConfig() *UserConfig {
TimeFormat: "02 Jan 06",
ShortTimeFormat: time.Kitchen,
Theme: ThemeConfig{
ActiveBorderColor: []string{"green", "bold"},
InactiveBorderColor: []string{"default"},
OptionsTextColor: []string{"blue"},
SelectedLineBgColor: []string{"blue"},
SelectedRangeBgColor: []string{"blue"},
CherryPickedCommitBgColor: []string{"cyan"},
CherryPickedCommitFgColor: []string{"blue"},
UnstagedChangesColor: []string{"red"},
DefaultFgColor: []string{"default"},
ActiveBorderColor: []string{"green", "bold"},
SearchingActiveBorderColor: []string{"cyan", "bold"},
InactiveBorderColor: []string{"default"},
OptionsTextColor: []string{"blue"},
SelectedLineBgColor: []string{"blue"},
SelectedRangeBgColor: []string{"blue"},
CherryPickedCommitBgColor: []string{"cyan"},
CherryPickedCommitFgColor: []string{"blue"},
UnstagedChangesColor: []string{"red"},
DefaultFgColor: []string{"default"},
},
CommitLength: CommitLengthConfig{Show: true},
SkipNoStagedFilesWarning: false,
Expand Down
14 changes: 14 additions & 0 deletions pkg/gui/controllers/helpers/search_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
func (self *SearchHelper) DisplaySearchStatusIfSearching(c types.Context) {
if searchableContext, ok := c.(types.ISearchableContext); ok {
if searchableContext.IsSearching() {
self.setSearchingFrameColor()
self.DisplaySearchStatus(searchableContext)
}
}
if filterableContext, ok := c.(types.IFilterableContext); ok {
if filterableContext.IsFiltering() {
self.setSearchingFrameColor()
self.DisplayFilterStatus(filterableContext)
}
}
Expand All @@ -232,6 +234,18 @@ func (self *SearchHelper) CancelSearchIfSearching(c types.Context) {
}

func (self *SearchHelper) HidePrompt() {
self.setNonSearchingFrameColor()

state := self.searchState()
state.Context = nil
}

func (self *SearchHelper) setSearchingFrameColor() {
self.c.GocuiGui().SelFgColor = theme.SearchingActiveBorderColor
self.c.GocuiGui().SelFrameColor = theme.SearchingActiveBorderColor
}

func (self *SearchHelper) setNonSearchingFrameColor() {
self.c.GocuiGui().SelFgColor = theme.ActiveBorderColor
self.c.GocuiGui().SelFrameColor = theme.ActiveBorderColor
}
11 changes: 5 additions & 6 deletions pkg/gui/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ func (gui *Gui) createAllViews() error {
gui.Views.Options.Frame = false

gui.Views.SearchPrefix.BgColor = gocui.ColorDefault
gui.Views.SearchPrefix.FgColor = gocui.ColorGreen
gui.Views.SearchPrefix.FgColor = gocui.ColorCyan
gui.Views.SearchPrefix.Frame = false
gui.c.SetViewContent(gui.Views.SearchPrefix, gui.Tr.SearchPrefix)

gui.Views.Search.BgColor = gocui.ColorDefault
gui.Views.Search.FgColor = gocui.ColorCyan
gui.Views.Search.Editable = true
gui.Views.Search.Frame = false
gui.Views.Search.Editor = gocui.EditorFunc(gui.searchEditor)

gui.Views.Stash.Title = gui.c.Tr.StashTitle
Expand Down Expand Up @@ -143,11 +147,6 @@ func (gui *Gui) createAllViews() error {

gui.Views.Status.Title = gui.c.Tr.StatusTitle

gui.Views.Search.BgColor = gocui.ColorDefault
gui.Views.Search.FgColor = gocui.ColorGreen
gui.Views.Search.Editable = true
gui.Views.Search.Frame = false

gui.Views.AppStatus.BgColor = gocui.ColorDefault
gui.Views.AppStatus.FgColor = gocui.ColorCyan
gui.Views.AppStatus.Visible = false
Expand Down
4 changes: 4 additions & 0 deletions pkg/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var (
// InactiveBorderColor is the border color of the inactive active frames
InactiveBorderColor gocui.Attribute

// FilteredActiveBorderColor is the border color of the active frame, when it's being searched/filtered
SearchingActiveBorderColor gocui.Attribute

// GocuiSelectedLineBgColor is the background color for the selected line in gocui
GocuiSelectedLineBgColor gocui.Attribute

Expand All @@ -44,6 +47,7 @@ var (
func UpdateTheme(themeConfig config.ThemeConfig) {
ActiveBorderColor = GetGocuiStyle(themeConfig.ActiveBorderColor)
InactiveBorderColor = GetGocuiStyle(themeConfig.InactiveBorderColor)
SearchingActiveBorderColor = GetGocuiStyle(themeConfig.SearchingActiveBorderColor)
SelectedLineBgColor = GetTextStyle(themeConfig.SelectedLineBgColor, true)
SelectedRangeBgColor = GetTextStyle(themeConfig.SelectedRangeBgColor, true)

Expand Down

0 comments on commit 9df634f

Please sign in to comment.