diff options
-rw-r--r-- | commands/account/cf.go | 2 | ||||
-rw-r--r-- | lib/statusline/folderstate.go | 28 | ||||
-rw-r--r-- | lib/statusline/state.go | 71 | ||||
-rw-r--r-- | widgets/account.go | 12 |
4 files changed, 67 insertions, 46 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go index ad93fdf6..b5cda53f 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -5,6 +5,7 @@ import ( "strings" "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/lib/statusline" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -52,6 +53,7 @@ func (ChangeFolder) Execute(aerc *widgets.Aerc, args []string) error { store := acct.Store() if store != nil { store.ApplyClear() + acct.SetStatus(statusline.SearchFilterClear()) } return nil } diff --git a/lib/statusline/folderstate.go b/lib/statusline/folderstate.go new file mode 100644 index 00000000..50a8c82b --- /dev/null +++ b/lib/statusline/folderstate.go @@ -0,0 +1,28 @@ +package statusline + +type folderState struct { + Search string + Filter string + FilterActivity string + + Threading string +} + +func (fs *folderState) State() []string { + var line []string + + if fs.FilterActivity != "" { + line = append(line, fs.FilterActivity) + } else { + if fs.Filter != "" { + line = append(line, fs.Filter) + } + } + if fs.Search != "" { + line = append(line, fs.Search) + } + if fs.Threading != "" { + line = append(line, fs.Threading) + } + return line +} 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" diff --git a/widgets/account.go b/widgets/account.go index 5d1315c2..1d319232 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -32,7 +32,6 @@ type AccountView struct { msglist *MessageList worker *types.Worker state *statusline.State - update bool } func (acct *AccountView) UiConfig() config.UIConfig { @@ -112,13 +111,13 @@ func (acct *AccountView) Tick() bool { func (acct *AccountView) SetStatus(setters ...statusline.SetStateFunc) { for _, fn := range setters { - fn(acct.state) + fn(acct.state, acct.SelectedDirectory()) } - acct.update = true + acct.UpdateStatus() } func (acct *AccountView) UpdateStatus() { - acct.host.SetStatus(acct.state.String()) + acct.host.SetStatus(acct.state.StatusLine(acct.SelectedDirectory())) } func (acct *AccountView) PushStatus(status string, expiry time.Duration) { @@ -160,10 +159,6 @@ func (acct *AccountView) Invalidate() { } func (acct *AccountView) Draw(ctx *ui.Context) { - if acct.update { - acct.UpdateStatus() - acct.update = false - } acct.grid.Draw(ctx) } @@ -322,6 +317,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.logger.Printf("%v", msg.Error) acct.PushError(msg.Error) } + acct.UpdateStatus() } func (acct *AccountView) getSortCriteria() []*types.SortCriterion { |