diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-04-16 09:53:46 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-04-22 22:40:12 +0200 |
commit | d8c2d63ee9b37e78d0e06ec71b2227b83ee52aa5 (patch) | |
tree | ea71295539f16c1f696dcb2edbca1475d93298a8 | |
parent | 669431702f46eb58f893cbe722040de3792f6b03 (diff) | |
download | aerc-d8c2d63ee9b37e78d0e06ec71b2227b83ee52aa5.tar.gz |
directory: add role to template fields
Add .Role as a template field for use in distinguishing between
mailboxes with a given IANA role, or custom role defined by aerc
("query" for notmuch queries, for example).
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry<robin@jarry.cc>
-rw-r--r-- | commands/commands.go | 4 | ||||
-rw-r--r-- | config/templates.go | 1 | ||||
-rw-r--r-- | doc/aerc-templates.7.scd | 6 | ||||
-rw-r--r-- | lib/state/templates.go | 22 | ||||
-rw-r--r-- | widgets/account.go | 2 | ||||
-rw-r--r-- | widgets/compose.go | 4 | ||||
-rw-r--r-- | widgets/dirlist.go | 2 | ||||
-rw-r--r-- | widgets/dirtree.go | 10 | ||||
-rw-r--r-- | widgets/msglist.go | 2 | ||||
-rw-r--r-- | widgets/status.go | 2 |
10 files changed, 40 insertions, 15 deletions
diff --git a/commands/commands.go b/commands/commands.go index cf96a39e..0a7050e9 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -75,11 +75,11 @@ func templateData( cfg *config.AccountConfig, msg *models.MessageInfo, ) models.TemplateData { - var folder string + var folder *models.Directory acct := aerc.SelectedAccount() if acct != nil { - folder = acct.SelectedDirectory() + folder = acct.Directories().SelectedDirectory() } if cfg == nil && acct != nil { cfg = acct.AccountConfig() diff --git a/config/templates.go b/config/templates.go index ff88689f..2b16fb22 100644 --- a/config/templates.go +++ b/config/templates.go @@ -98,6 +98,7 @@ func (d *dummyData) ContentInfo() string { return "" } func (d *dummyData) StatusInfo() string { return "" } func (d *dummyData) TrayInfo() string { return "" } func (d *dummyData) PendingKeys() string { return "" } +func (d *dummyData) Role() string { return "inbox" } func (d *dummyData) Style(string, string) string { return "" } func (d *dummyData) StyleSwitch(string, ...models.Case) string { return "" } diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd index c7830b8b..ae9bc6dc 100644 --- a/doc/aerc-templates.7.scd +++ b/doc/aerc-templates.7.scd @@ -162,6 +162,12 @@ available always. {{.RUE}} ``` + IANA role of the mailbox, converted to lowercase. aerc uses one custom + role: 'query', which is given to mailboxes from a notmuch query-map + ``` + {{if eq .Role "query"}}{{...}}{{else}}{{...}}{{end}} + ``` + Current message counts for specific folders: ``` diff --git a/lib/state/templates.go b/lib/state/templates.go index f971b62c..e93d0bb0 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -29,7 +29,7 @@ type TemplateData struct { // selected account account *config.AccountConfig myAddresses map[string]bool - folder string // selected folder name + folder *models.Directory // selected folder folders []string getRUEcount func(string) (int, int, int) @@ -66,7 +66,7 @@ func (d *TemplateData) SetAccount(acct *config.AccountConfig) { } } -func (d *TemplateData) SetFolder(folder string) { +func (d *TemplateData) SetFolder(folder *models.Directory) { d.folder = folder } @@ -91,11 +91,21 @@ func (d *TemplateData) Account() string { } func (d *TemplateData) Folder() string { - return d.folder + if d.folder != nil { + return d.folder.Name + } + return "" +} + +func (d *TemplateData) Role() string { + if d.folder != nil { + return string(d.folder.Role) + } + return "" } func (d *TemplateData) ui() *config.UIConfig { - return config.Ui.ForAccount(d.Account()).ForFolder(d.folder) + return config.Ui.ForAccount(d.Account()).ForFolder(d.Folder()) } func (d *TemplateData) To() []*mail.Address { @@ -425,7 +435,7 @@ func (d *TemplateData) ContentInfo() string { return "" } var content []string - fldr := d.state.folderState(d.folder) + fldr := d.state.folderState(d.Folder()) if fldr.FilterActivity != "" { content = append(content, fldr.FilterActivity) } else if fldr.Filter != "" { @@ -450,7 +460,7 @@ func (d *TemplateData) TrayInfo() string { return "" } var tray []string - fldr := d.state.folderState(d.folder) + fldr := d.state.folderState(d.Folder()) if fldr.Sorting { tray = append(tray, texter().Sorting()) } diff --git a/widgets/account.go b/widgets/account.go index 983c2382..a99f7a48 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -606,7 +606,7 @@ func (acct *AccountView) setTitle() { return } data.SetAccount(acct.acct) - data.SetFolder(acct.SelectedDirectory()) + data.SetFolder(acct.Directories().SelectedDirectory()) data.SetRUE(acct.dirlist.List(), acct.dirlist.GetRUECount) var buf bytes.Buffer diff --git a/widgets/compose.go b/widgets/compose.go index 3693ad18..3a960325 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -98,7 +98,7 @@ func NewComposer( var data state.TemplateData data.SetAccount(acct.acct) - data.SetFolder(acct.Directories().Selected()) + data.SetFolder(acct.Directories().SelectedDirectory()) data.SetHeaders(h, orig) if err := c.AddTemplate(template, &data); err != nil { return nil, err @@ -1589,7 +1589,7 @@ func (c *Composer) setTitle() { header.SetSubject("New Email") } data.SetAccount(c.acctConfig) - data.SetFolder(c.acct.SelectedDirectory()) + data.SetFolder(c.acct.Directories().SelectedDirectory()) data.SetHeaders(&header, c.parent) var buf bytes.Buffer diff --git a/widgets/dirlist.go b/widgets/dirlist.go index ee2acb1b..da2fa69a 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -247,7 +247,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) { break } - data.SetFolder(name) + data.SetFolder(dirlist.Directory(name)) data.SetRUE([]string{name}, dirlist.GetRUECount) left, right, style := dirlist.renderDir( name, uiConfig, &data, diff --git a/widgets/dirtree.go b/widgets/dirtree.go index 88e930ec..b0943ae4 100644 --- a/widgets/dirtree.go +++ b/widgets/dirtree.go @@ -11,6 +11,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/state" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" + "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/gdamore/tcell/v2" ) @@ -106,7 +107,14 @@ func (dt *DirectoryTree) Draw(ctx *ui.Context) { } path := dt.getDirectory(node) - data.SetFolder(dt.displayText(node)) + dir := dt.Directory(path) + treeDir := &models.Directory{ + Name: dt.displayText(node), + } + if dir != nil { + treeDir.Role = dir.Role + } + data.SetFolder(treeDir) data.SetRUE([]string{path}, dt.GetRUECount) left, right, style := dt.renderDir( diff --git a/widgets/msglist.go b/widgets/msglist.go index 161dcadc..45d2555c 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -94,7 +94,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { var data state.TemplateData data.SetAccount(acct.acct) - data.SetFolder(acct.Directories().Selected()) + data.SetFolder(acct.Directories().SelectedDirectory()) customDraw := func(t *ui.Table, r int, c *ui.Context) bool { row := &t.Rows[r] diff --git a/widgets/status.go b/widgets/status.go index 209348c5..9f2544c7 100644 --- a/widgets/status.go +++ b/widgets/status.go @@ -53,7 +53,7 @@ func (status *StatusLine) Draw(ctx *ui.Context) { data.SetPendingKeys(status.aerc.pendingKeys) data.SetState(&status.acct.state) data.SetAccount(status.acct.acct) - data.SetFolder(status.acct.Directories().Selected()) + data.SetFolder(status.acct.Directories().SelectedDirectory()) msg, _ := status.acct.SelectedMessage() data.SetInfo(msg, 0, false) table := ui.NewTable( |