aboutsummaryrefslogtreecommitdiffstats
path: root/lib/state/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/state/state.go')
-rw-r--r--lib/state/state.go86
1 files changed, 24 insertions, 62 deletions
diff --git a/lib/state/state.go b/lib/state/state.go
index b5f925ac..49431029 100644
--- a/lib/state/state.go
+++ b/lib/state/state.go
@@ -2,27 +2,16 @@ package state
import (
"fmt"
-
- "git.sr.ht/~rjarry/aerc/config"
)
-type State struct {
- renderer renderFunc
- acct *accountState
- fldr map[string]*folderState
- width int
-}
-
-type accountState struct {
- Name string
- Multiple bool
- ConnActivity string
+type AccountState struct {
Connected bool
- Passthrough bool
+ connActivity string
+ passthrough bool
+ folders map[string]*folderState
}
type folderState struct {
- Name string
Search string
Filter string
FilterActivity string
@@ -30,60 +19,33 @@ type folderState struct {
Threading bool
}
-func NewState(name string, multipleAccts bool) *State {
- return &State{
- renderer: newRenderer(),
- acct: &accountState{Name: name, Multiple: multipleAccts},
- fldr: make(map[string]*folderState),
- }
-}
-
-func (s *State) StatusLine(folder string) string {
- return s.renderer(renderParams{
- width: s.width,
- sep: config.Statusline.Separator,
- acct: s.acct,
- fldr: s.folderState(folder),
- })
-}
-
-func (s *State) folderState(folder string) *folderState {
- if _, ok := s.fldr[folder]; !ok {
- s.fldr[folder] = &folderState{Name: folder}
+func (s *AccountState) folderState(folder string) *folderState {
+ if s.folders == nil {
+ s.folders = make(map[string]*folderState)
}
- return s.fldr[folder]
-}
-
-func (s *State) SetWidth(w int) bool {
- changeState := false
- if s.width != w {
- s.width = w
- changeState = true
+ if _, ok := s.folders[folder]; !ok {
+ s.folders[folder] = &folderState{}
}
- return changeState
-}
-
-func (s *State) Connected() bool {
- return s.acct.Connected
+ return s.folders[folder]
}
-type SetStateFunc func(s *State, folder string)
+type SetStateFunc func(s *AccountState, folder string)
func SetConnected(state bool) SetStateFunc {
- return func(s *State, folder string) {
- s.acct.ConnActivity = ""
- s.acct.Connected = state
+ return func(s *AccountState, folder string) {
+ s.connActivity = ""
+ s.Connected = state
}
}
func ConnectionActivity(desc string) SetStateFunc {
- return func(s *State, folder string) {
- s.acct.ConnActivity = desc
+ return func(s *AccountState, folder string) {
+ s.connActivity = desc
}
}
func SearchFilterClear() SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).Search = ""
s.folderState(folder).FilterActivity = ""
s.folderState(folder).Filter = ""
@@ -91,13 +53,13 @@ func SearchFilterClear() SetStateFunc {
}
func FilterActivity(str string) SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).FilterActivity = str
}
}
func FilterResult(str string) SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).FilterActivity = ""
s.folderState(folder).Filter = concatFilters(s.folderState(folder).Filter, str)
}
@@ -111,25 +73,25 @@ func concatFilters(existing, next string) string {
}
func Search(desc string) SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).Search = desc
}
}
func Sorting(on bool) SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).Sorting = on
}
}
func Threading(on bool) SetStateFunc {
- return func(s *State, folder string) {
+ return func(s *AccountState, folder string) {
s.folderState(folder).Threading = on
}
}
func Passthrough(on bool) SetStateFunc {
- return func(s *State, folder string) {
- s.acct.Passthrough = on
+ return func(s *AccountState, folder string) {
+ s.passthrough = on
}
}