diff options
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" |