diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-03-21 22:18:51 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-03-23 20:55:30 +0100 |
commit | feecc09b73e2c904be42f271e0c10574b98a95ea (patch) | |
tree | 3bc763d021ad55f42debfa326ed2340f0ae06b2b /lib/statusline/state.go | |
parent | e56648029f2231a58ed4afbbe804b845e02fde62 (diff) | |
download | aerc-feecc09b73e2c904be42f271e0c10574b98a95ea.tar.gz |
statusline: make statusline folder-specific
Make statusline folder-specific. Update filter, search and threading
status when changing folders.
Commit 2512c04 ("statusline: implement per-account status") introduced
an account-specific statusline. This makes it account- and
folder-specific.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'lib/statusline/state.go')
-rw-r--r-- | lib/statusline/state.go | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/lib/statusline/state.go b/lib/statusline/state.go index 30029c13..fe32626a 100644 --- a/lib/statusline/state.go +++ b/lib/statusline/state.go @@ -14,19 +14,17 @@ type State struct { ConnActivity string Connected bool - Search string - Filter string - FilterActivity string - - Threading string Passthrough string + + fs map[string]*folderState } func NewState(name string, multipleAccts bool, sep string) *State { - return &State{Name: name, Multiple: multipleAccts, Separator: sep} + return &State{Name: name, Multiple: multipleAccts, Separator: sep, + fs: make(map[string]*folderState)} } -func (s *State) String() string { +func (s *State) StatusLine(folder string) string { var line []string if s.Connection != "" || s.ConnActivity != "" { conn := s.Connection @@ -40,30 +38,27 @@ func (s *State) String() string { } } if s.Connected { - if s.FilterActivity != "" { - line = append(line, s.FilterActivity) - } else { - if s.Filter != "" { - line = append(line, s.Filter) - } - } - if s.Search != "" { - line = append(line, s.Search) - } - if s.Threading != "" { - line = append(line, s.Threading) - } if s.Passthrough != "" { line = append(line, s.Passthrough) } + if folder != "" { + line = append(line, s.folderState(folder).State()...) + } } return strings.Join(line, s.Separator) } -type SetStateFunc func(s *State) +func (s *State) folderState(folder string) *folderState { + if _, ok := s.fs[folder]; !ok { + s.fs[folder] = &folderState{} + } + return s.fs[folder] +} + +type SetStateFunc func(s *State, folder string) func Connected(state bool) SetStateFunc { - return func(s *State) { + return func(s *State, folder string) { s.ConnActivity = "" s.Connected = state if state { @@ -75,29 +70,29 @@ func Connected(state bool) SetStateFunc { } func ConnectionActivity(desc string) SetStateFunc { - return func(s *State) { + return func(s *State, folder string) { s.ConnActivity = desc } } func SearchFilterClear() SetStateFunc { - return func(s *State) { - s.Search = "" - s.FilterActivity = "" - s.Filter = "" + return func(s *State, folder string) { + s.folderState(folder).Search = "" + s.folderState(folder).FilterActivity = "" + s.folderState(folder).Filter = "" } } func FilterActivity(str string) SetStateFunc { - return func(s *State) { - s.FilterActivity = str + return func(s *State, folder string) { + s.folderState(folder).FilterActivity = str } } func FilterResult(str string) SetStateFunc { - return func(s *State) { - s.FilterActivity = "" - s.Filter = concatFilters(s.Filter, str) + return func(s *State, folder string) { + s.folderState(folder).FilterActivity = "" + s.folderState(folder).Filter = concatFilters(s.folderState(folder).Filter, str) } } @@ -109,22 +104,22 @@ func concatFilters(existing, next string) string { } func Search(desc string) SetStateFunc { - return func(s *State) { - s.Search = desc + return func(s *State, folder string) { + s.folderState(folder).Search = desc } } func Threading(on bool) SetStateFunc { - return func(s *State) { - s.Threading = "" + return func(s *State, folder string) { + s.folderState(folder).Threading = "" if on { - s.Threading = "threading" + s.folderState(folder).Threading = "threading" } } } func Passthrough(on bool) SetStateFunc { - return func(s *State) { + return func(s *State, folder string) { s.Passthrough = "" if on { s.Passthrough = "passthrough" |