diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-03-18 22:35:33 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-03-18 23:42:07 +0100 |
commit | 2512c0403fa42b19c3e87fed44240da045ec902f (patch) | |
tree | a258d6a9c70e79cf316985363efcdc9529c91924 /lib/statusline/state.go | |
parent | 807870ea3542f2fcb00e7e0451af37c224041dfe (diff) | |
download | aerc-2512c0403fa42b19c3e87fed44240da045ec902f.tar.gz |
statusline: implement per-account status
Implement a statusline state for each account. Keep the ex line and the
push notifications global. Add account name prefix to push
notifications. Prefix status line with account name when multiple
accounts are available.
Use account-specific status line for each tab where an account is
defined.
Handle threading, filter/search, viewer passthrough and connection
status.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/statusline/state.go')
-rw-r--r-- | lib/statusline/state.go | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/statusline/state.go b/lib/statusline/state.go new file mode 100644 index 00000000..30029c13 --- /dev/null +++ b/lib/statusline/state.go @@ -0,0 +1,133 @@ +package statusline + +import ( + "fmt" + "strings" +) + +type State struct { + Name string + Multiple bool + Separator string + + Connection string + ConnActivity string + Connected bool + + Search string + Filter string + FilterActivity string + + Threading string + Passthrough string +} + +func NewState(name string, multipleAccts bool, sep string) *State { + return &State{Name: name, Multiple: multipleAccts, Separator: sep} +} + +func (s *State) String() string { + var line []string + if s.Connection != "" || s.ConnActivity != "" { + conn := s.Connection + if s.ConnActivity != "" { + conn = s.ConnActivity + } + if s.Multiple { + line = append(line, fmt.Sprintf("[%s] %s", s.Name, conn)) + } else { + line = append(line, conn) + } + } + 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) + } + } + return strings.Join(line, s.Separator) +} + +type SetStateFunc func(s *State) + +func Connected(state bool) SetStateFunc { + return func(s *State) { + s.ConnActivity = "" + s.Connected = state + if state { + s.Connection = "Connected" + } else { + s.Connection = "Disconnected" + } + } +} + +func ConnectionActivity(desc string) SetStateFunc { + return func(s *State) { + s.ConnActivity = desc + } +} + +func SearchFilterClear() SetStateFunc { + return func(s *State) { + s.Search = "" + s.FilterActivity = "" + s.Filter = "" + } +} + +func FilterActivity(str string) SetStateFunc { + return func(s *State) { + s.FilterActivity = str + } +} + +func FilterResult(str string) SetStateFunc { + return func(s *State) { + s.FilterActivity = "" + s.Filter = concatFilters(s.Filter, str) + } +} + +func concatFilters(existing, next string) string { + if existing == "" { + return next + } + return fmt.Sprintf("%s && %s", existing, next) +} + +func Search(desc string) SetStateFunc { + return func(s *State) { + s.Search = desc + } +} + +func Threading(on bool) SetStateFunc { + return func(s *State) { + s.Threading = "" + if on { + s.Threading = "threading" + } + } +} + +func Passthrough(on bool) SetStateFunc { + return func(s *State) { + s.Passthrough = "" + if on { + s.Passthrough = "passthrough" + } + } +} |