aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAron Lebani <aron@lebani.dev>2024-08-02 09:59:33 +1000
committerRobin Jarry <robin@jarry.cc>2024-08-04 18:26:58 +0200
commitfff69046b02f3d9ea0218ff071ba5e4d5b3a3c12 (patch)
tree3537292b6b3070a44196629c6df3b544ce4d3c04
parent2cd0cec19d6146d6e9681b648d978f463b107008 (diff)
downloadaerc-fff69046b02f3d9ea0218ff071ba5e4d5b3a3c12.tar.gz
view-message: add option to view message in background tab
Add a -b flag to the :view command to open messages in a background tab instead of automatically switching to the new tab after opening. This is similar to opening browser tabs in the background. More generally, adds a new function app.NewBackgroundTab so that it is possible to enable other tabs to be opened in the background in the future. Implements: https://todo.sr.ht/~rjarry/aerc/266 Changelog-added: Add `-b` flag to the `:view` command to open messages in a background tab. Signed-off-by: Aron Lebani <aron@lebani.dev> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--app/aerc.go16
-rw-r--r--app/app.go35
-rw-r--r--commands/account/view.go17
-rw-r--r--doc/aerc.1.scd7
-rw-r--r--lib/ui/tab.go8
5 files changed, 52 insertions, 31 deletions
diff --git a/app/aerc.go b/app/aerc.go
index b6bc2430..38340c7d 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -88,17 +88,17 @@ func (aerc *Aerc) Init(
for _, acct := range config.Accounts {
view, err := NewAccountView(acct, deferLoop)
if err != nil {
- tabs.Add(errorScreen(err.Error()), acct.Name, nil)
+ tabs.Add(errorScreen(err.Error()), acct.Name, nil, false)
} else {
aerc.accounts[acct.Name] = view
- view.tab = tabs.Add(view, acct.Name, view.UiConfig())
+ view.tab = tabs.Add(view, acct.Name, view.UiConfig(), false)
}
}
if len(config.Accounts) == 0 {
wizard := NewAccountWizard()
wizard.Focus(true)
- aerc.NewTab(wizard, "New account")
+ aerc.NewTab(wizard, "New account", false)
}
tabs.Select(0)
@@ -503,12 +503,12 @@ func (aerc *Aerc) SelectedTab() *ui.Tab {
return aerc.tabs.Selected()
}
-func (aerc *Aerc) NewTab(clickable ui.Drawable, name string) *ui.Tab {
+func (aerc *Aerc) NewTab(clickable ui.Drawable, name string, background bool) *ui.Tab {
uiConf := config.Ui
if acct := aerc.account(clickable); acct != nil {
uiConf = acct.UiConfig()
}
- tab := aerc.tabs.Add(clickable, name, uiConf)
+ tab := aerc.tabs.Add(clickable, name, uiConf, background)
aerc.UpdateStatus()
return tab
}
@@ -806,7 +806,7 @@ func (aerc *Aerc) mailto(addr *url.URL) error {
if to == nil {
composer.FocusEditor("to")
}
- composer.Tab = aerc.NewTab(composer, title)
+ composer.Tab = aerc.NewTab(composer, title, false)
for _, file := range attachments {
composer.AddAttachment(file)
@@ -835,10 +835,10 @@ func (aerc *Aerc) mbox(source string) error {
mboxView, err := NewAccountView(&acctConf, nil)
if err != nil {
- aerc.NewTab(errorScreen(err.Error()), acctConf.Name)
+ aerc.NewTab(errorScreen(err.Error()), acctConf.Name, false)
} else {
aerc.accounts[acctConf.Name] = mboxView
- aerc.NewTab(mboxView, acctConf.Name)
+ aerc.NewTab(mboxView, acctConf.Name, false)
}
return nil
}
diff --git a/app/app.go b/app/app.go
index 7e06ce3b..ad38e720 100644
--- a/app/app.go
+++ b/app/app.go
@@ -45,20 +45,27 @@ func PrevAccount() (*AccountView, error) { return aerc.PrevAccount() }
func SelectedAccount() *AccountView { return aerc.SelectedAccount() }
func SelectedAccountUiConfig() *config.UIConfig { return aerc.SelectedAccountUiConfig() }
-func NextTab() { aerc.NextTab() }
-func PrevTab() { aerc.PrevTab() }
-func PinTab() { aerc.PinTab() }
-func UnpinTab() { aerc.UnpinTab() }
-func MoveTab(i int, relative bool) { aerc.MoveTab(i, relative) }
-func TabNames() []string { return aerc.TabNames() }
-func SelectTab(name string) bool { return aerc.SelectTab(name) }
-func SelectPreviousTab() bool { return aerc.SelectPreviousTab() }
-func SelectedTab() *ui.Tab { return aerc.SelectedTab() }
-func SelectedTabContent() ui.Drawable { return aerc.SelectedTabContent() }
-func SelectTabIndex(index int) bool { return aerc.SelectTabIndex(index) }
-func SelectTabAtOffset(offset int) { aerc.SelectTabAtOffset(offset) }
-func RemoveTab(tab ui.Drawable, closeContent bool) { aerc.RemoveTab(tab, closeContent) }
-func NewTab(clickable ui.Drawable, name string) *ui.Tab { return aerc.NewTab(clickable, name) }
+func NextTab() { aerc.NextTab() }
+func PrevTab() { aerc.PrevTab() }
+func PinTab() { aerc.PinTab() }
+func UnpinTab() { aerc.UnpinTab() }
+func MoveTab(i int, relative bool) { aerc.MoveTab(i, relative) }
+func TabNames() []string { return aerc.TabNames() }
+func SelectTab(name string) bool { return aerc.SelectTab(name) }
+func SelectPreviousTab() bool { return aerc.SelectPreviousTab() }
+func SelectedTab() *ui.Tab { return aerc.SelectedTab() }
+func SelectedTabContent() ui.Drawable { return aerc.SelectedTabContent() }
+func SelectTabIndex(index int) bool { return aerc.SelectTabIndex(index) }
+func SelectTabAtOffset(offset int) { aerc.SelectTabAtOffset(offset) }
+func RemoveTab(tab ui.Drawable, closeContent bool) { aerc.RemoveTab(tab, closeContent) }
+func NewTab(clickable ui.Drawable, name string) *ui.Tab {
+ return aerc.NewTab(clickable, name, false)
+}
+
+func NewBackgroundTab(clickable ui.Drawable, name string) *ui.Tab {
+ return aerc.NewTab(clickable, name, true)
+}
+
func ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string, closeSrc bool) {
aerc.ReplaceTab(tabSrc, tabTarget, name, closeSrc)
}
diff --git a/commands/account/view.go b/commands/account/view.go
index 9fa531b7..58450044 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -13,7 +13,8 @@ import (
)
type ViewMessage struct {
- Peek bool `opt:"-p"`
+ Peek bool `opt:"-p"`
+ Background bool `opt:"-b"`
}
func init() {
@@ -49,8 +50,12 @@ func (v ViewMessage) Execute(args []string) error {
app.PushError(msg.Error.Error())
return nil
}
- lib.NewMessageStoreView(msg, !v.Peek && acct.UiConfig().AutoMarkRead,
- store, app.CryptoProvider(), app.DecryptKeys,
+ lib.NewMessageStoreView(
+ msg,
+ !v.Peek && acct.UiConfig().AutoMarkRead,
+ store,
+ app.CryptoProvider(),
+ app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
app.PushError(err.Error())
@@ -68,7 +73,11 @@ func (v ViewMessage) Execute(args []string) error {
acct.PushError(err)
return
}
- app.NewTab(viewer, buf.String())
+ if v.Background {
+ app.NewBackgroundTab(viewer, buf.String())
+ } else {
+ app.NewTab(viewer, buf.String())
+ }
})
return nil
}
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 0e9f33ef..30840158 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -713,11 +713,12 @@ message list, the message in the message viewer, etc).
Toggles between showing entire thread (when supported) and only showing
messages which match the current query / mailbox.
-*:view* [*-p*]++
-*:view-message* [*-p*]
+*:view* [*-pb*]++
+*:view-message* [*-pb*]
Opens the message viewer to display the selected message. If the peek
flag *-p* is set, the message will not be marked as seen and ignores the
- *auto-mark-read* config.
+ *auto-mark-read* config. If the background flag *-b* is set, the message
+ will be opened in a background tab.
*:vsplit* [[_+_|_-_]_<n>_]
Creates a vertical split of the message list. The message list will be
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 5d824955..64e4155a 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -65,14 +65,18 @@ func NewTabs(uiConf *config.UIConfig) *Tabs {
return tabs
}
-func (tabs *Tabs) Add(content Drawable, name string, uiConf *config.UIConfig) *Tab {
+func (tabs *Tabs) Add(
+ content Drawable, name string, uiConf *config.UIConfig, background bool,
+) *Tab {
tab := &Tab{
Content: content,
Name: name,
uiConf: uiConf,
}
tabs.tabs = append(tabs.tabs, tab)
- tabs.selectPriv(len(tabs.tabs) - 1)
+ if !background {
+ tabs.selectPriv(len(tabs.tabs) - 1)
+ }
return tab
}