aerc: use contextual ui styleset for tabs/compose

Use contextual ui styleset for tabs and compose widgets. If no account
is selected, use default styleset as fallback.

Fixes: https://todo.sr.ht/~rjarry/aerc/3
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-04-17 01:03:49 +02:00 committed by Robin Jarry
parent 1ecee8efa5
commit 6edfbfa8ce
2 changed files with 24 additions and 8 deletions

View File

@ -31,6 +31,7 @@ type Tab struct {
invalid bool
pinned bool
indexBeforePin int
uiConf *config.UIConfig
}
type TabStrip Tabs
@ -47,10 +48,11 @@ func NewTabs(uiConf *config.UIConfig) *Tabs {
return tabs
}
func (tabs *Tabs) Add(content Drawable, name string) *Tab {
func (tabs *Tabs) Add(content Drawable, name string, uiConf *config.UIConfig) *Tab {
tab := &Tab{
Content: content,
Name: name,
uiConf: uiConf,
}
tabs.Tabs = append(tabs.Tabs, tab)
tabs.TabStrip.Invalidate()
@ -283,9 +285,13 @@ func (tabs *Tabs) removeHistory(index int) {
func (strip *TabStrip) Draw(ctx *Context) {
x := 0
for i, tab := range strip.Tabs {
style := strip.uiConfig.GetStyle(config.STYLE_TAB)
uiConfig := strip.uiConfig
if tab.uiConf != nil {
uiConfig = tab.uiConf
}
style := uiConfig.GetStyle(config.STYLE_TAB)
if strip.Selected == i {
style = strip.uiConfig.GetStyleSelected(config.STYLE_TAB)
style = uiConfig.GetStyleSelected(config.STYLE_TAB)
}
tabWidth := 32
if ctx.Width()-x < tabWidth {
@ -293,7 +299,7 @@ func (strip *TabStrip) Draw(ctx *Context) {
}
name := tab.Name
if tab.pinned {
name = strip.uiConfig.PinnedTabMarker + name
name = uiConfig.PinnedTabMarker + name
}
trunc := runewidth.Truncate(name, tabWidth, "…")
x += ctx.Printf(x, 0, style, " %s ", trunc)

View File

@ -87,10 +87,11 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
for i, acct := range conf.Accounts {
view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc, deferLoop)
if err != nil {
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name)
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name, nil)
} else {
aerc.accounts[acct.Name] = view
tabs.Add(view, acct.Name)
conf := view.UiConfig()
tabs.Add(view, acct.Name, &conf)
}
}
@ -303,7 +304,11 @@ func (aerc *Aerc) Logger() *log.Logger {
}
func (aerc *Aerc) SelectedAccount() *AccountView {
switch tab := aerc.SelectedTab().(type) {
return aerc.account(aerc.SelectedTab())
}
func (aerc *Aerc) account(d ui.Drawable) *AccountView {
switch tab := d.(type) {
case *AccountView:
return tab
case *MessageViewer:
@ -335,7 +340,12 @@ func (aerc *Aerc) NumTabs() int {
}
func (aerc *Aerc) NewTab(clickable ui.Drawable, name string) *ui.Tab {
tab := aerc.tabs.Add(clickable, name)
var uiConf *config.UIConfig = nil
if acct := aerc.account(clickable); acct != nil {
conf := acct.UiConfig()
uiConf = &conf
}
tab := aerc.tabs.Add(clickable, name, uiConf)
aerc.tabs.Select(len(aerc.tabs.Tabs) - 1)
aerc.UpdateStatus()
return tab