Skip to content

Commit

Permalink
ui: make viewer tab title configurable via templates
Browse files Browse the repository at this point in the history
We had account and composer tab title configuration fields already, but
not for viewer. Add tab-title-viewer configuration, which defaults to
Subject if it is not empty and to "(no subject)" when it is empty.

Changelog-added: New `[ui].tab-title-viewer` setting to configure the
 message viewer tab title.
Changelog-changed: Message viewer tab titles will now show `(no subject)`
 if there is no subject in the viewed email.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
  • Loading branch information
ferdinandyb authored and rjarry committed Nov 22, 2023
1 parent 019a1a5 commit 91b26ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion commands/account/view.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package account

import (
"bytes"
"errors"

"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/templates"
"git.sr.ht/~rjarry/aerc/models"
)

type ViewMessage struct {
Expand Down Expand Up @@ -48,7 +52,18 @@ func (v ViewMessage) Execute(args []string) error {
return
}
viewer := app.NewMessageViewer(acct, view)
app.NewTab(viewer, msg.Envelope.Subject)
data := state.NewDataSetter()
data.SetAccount(acct.AccountConfig())
data.SetFolder(acct.Directories().SelectedDirectory())
data.SetHeaders(msg.RFC822Headers, &models.OriginalMail{})
var buf bytes.Buffer
err = templates.Render(acct.UiConfig().TabTitleViewer, &buf,
data.Data())
if err != nil {
acct.PushError(err)
return
}
app.NewTab(viewer, buf.String())
})
return nil
}
1 change: 1 addition & 0 deletions config/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type UIConfig struct {
// Tab Templates
TabTitleAccount *template.Template `ini:"tab-title-account" default:"{{.Account}}"`
TabTitleComposer *template.Template `ini:"tab-title-composer" default:"{{.Subject}}"`
TabTitleViewer *template.Template `ini:"tab-title-viewer" default:"{{if .Subject}}{{.Subject}}{{else}}(no subject){{end}}"`

// private
contextualUis []*UiConfigContext
Expand Down
6 changes: 6 additions & 0 deletions doc/aerc-config.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ These options are configured in the *[ui]* section of _aerc.conf_.

Default: _{{.Subject}}_

*tab-title-viewer* = _<go_template>_
The template to use for viewer tab titles. See *aerc-templates*(7) for
available field names.

Default: _{{if .Subject}}{{.Subject}}{{else}}(no subject){{end}}_

*pinned-tab-marker* = _"<string>"_
Marker to show before a pinned tab's name.

Expand Down

0 comments on commit 91b26ad

Please sign in to comment.