mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
In the spirit of commit 535300cfdb ("config: add columns based index
format"), reuse the column definitions and table widget.
Add automatic translation of render-format to column definitions. Allow
empty columns to be compatible with the %m (mute) flag.
Rename the State object to AccountState to be more precise. Reuse that
object in state.TempateData to expose account state info. Move actual
status line rendering in StatusLine.Draw().
Add new template fields for status specific data:
{{.ConnectionInfo}}
Connection state.
{{.ContentInfo}}
General status information (e.g. filter, search)
{{.StatusInfo}}
Combination of {{.ConnectionInfo}} and {{.StatusInfo}}
{{.TrayInfo}}
General on/off information (e.g. passthrough, threading,
sorting)
{{.PendingKeys}}
Currently pressed key sequence that does not match any key
binding and/or is incomplete.
Display a warning on startup if render-format has been converted to
status-columns.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
98 lines
2.0 KiB
Go
98 lines
2.0 KiB
Go
package state
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type AccountState struct {
|
|
Connected bool
|
|
connActivity string
|
|
passthrough bool
|
|
folders map[string]*folderState
|
|
}
|
|
|
|
type folderState struct {
|
|
Search string
|
|
Filter string
|
|
FilterActivity string
|
|
Sorting bool
|
|
Threading bool
|
|
}
|
|
|
|
func (s *AccountState) folderState(folder string) *folderState {
|
|
if s.folders == nil {
|
|
s.folders = make(map[string]*folderState)
|
|
}
|
|
if _, ok := s.folders[folder]; !ok {
|
|
s.folders[folder] = &folderState{}
|
|
}
|
|
return s.folders[folder]
|
|
}
|
|
|
|
type SetStateFunc func(s *AccountState, folder string)
|
|
|
|
func SetConnected(state bool) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.connActivity = ""
|
|
s.Connected = state
|
|
}
|
|
}
|
|
|
|
func ConnectionActivity(desc string) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.connActivity = desc
|
|
}
|
|
}
|
|
|
|
func SearchFilterClear() SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.folderState(folder).Search = ""
|
|
s.folderState(folder).FilterActivity = ""
|
|
s.folderState(folder).Filter = ""
|
|
}
|
|
}
|
|
|
|
func FilterActivity(str string) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.folderState(folder).FilterActivity = str
|
|
}
|
|
}
|
|
|
|
func FilterResult(str string) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.folderState(folder).FilterActivity = ""
|
|
s.folderState(folder).Filter = concatFilters(s.folderState(folder).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 *AccountState, folder string) {
|
|
s.folderState(folder).Search = desc
|
|
}
|
|
}
|
|
|
|
func Sorting(on bool) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.folderState(folder).Sorting = on
|
|
}
|
|
}
|
|
|
|
func Threading(on bool) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.folderState(folder).Threading = on
|
|
}
|
|
}
|
|
|
|
func Passthrough(on bool) SetStateFunc {
|
|
return func(s *AccountState, folder string) {
|
|
s.passthrough = on
|
|
}
|
|
}
|