uiconfig: use pointer references to uiConfig

This patch changes references to uiConfig in function signatures and
structs to be pointers.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-03 10:11:12 -05:00 committed by Robin Jarry
parent 12e8217d1f
commit d45c07eb6a
15 changed files with 48 additions and 48 deletions

View File

@ -1017,14 +1017,14 @@ func (config AercConfig) mergeContextualUi(baseUi UIConfig,
return baseUi return baseUi
} }
func (config AercConfig) GetUiConfig(params map[ContextType]string) UIConfig { func (config AercConfig) GetUiConfig(params map[ContextType]string) *UIConfig {
baseUi := config.Ui baseUi := config.Ui
for k, v := range params { for k, v := range params {
baseUi = config.mergeContextualUi(baseUi, k, v) baseUi = config.mergeContextualUi(baseUi, k, v)
} }
return baseUi return &baseUi
} }
func (uiConfig UIConfig) GetStyle(so StyleObject) tcell.Style { func (uiConfig UIConfig) GetStyle(so StyleObject) tcell.Style {

View File

@ -18,11 +18,11 @@ type Bordered struct {
borders uint borders uint
content Drawable content Drawable
onInvalidate func(d Drawable) onInvalidate func(d Drawable)
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func NewBordered( func NewBordered(
content Drawable, borders uint, uiConfig config.UIConfig) *Bordered { content Drawable, borders uint, uiConfig *config.UIConfig) *Bordered {
b := &Bordered{ b := &Bordered{
borders: borders, borders: borders,
content: content, content: content,

View File

@ -33,13 +33,13 @@ type TextInput struct {
completeIndex int completeIndex int
completeDelay time.Duration completeDelay time.Duration
completeDebouncer *time.Timer completeDebouncer *time.Timer
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
// Creates a new TextInput. TextInputs will render a "textbox" in the entire // Creates a new TextInput. TextInputs will render a "textbox" in the entire
// context they're given, and process keypresses to build a string from user // context they're given, and process keypresses to build a string from user
// input. // input.
func NewTextInput(text string, ui config.UIConfig) *TextInput { func NewTextInput(text string, ui *config.UIConfig) *TextInput {
return &TextInput{ return &TextInput{
cells: -1, cells: -1,
text: []rune(text), text: []rune(text),
@ -383,7 +383,7 @@ type completions struct {
onSelect func(int) onSelect func(int)
onExec func() onExec func()
onStem func(string) onStem func(string)
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func maxLen(ss []string) int { func maxLen(ss []string) int {

View File

@ -75,21 +75,21 @@ type AccountWizard struct {
func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
wizard := &AccountWizard{ wizard := &AccountWizard{
accountName: ui.NewTextInput("", conf.Ui).Prompt("> "), accountName: ui.NewTextInput("", &conf.Ui).Prompt("> "),
aerc: aerc, aerc: aerc,
conf: conf, conf: conf,
temporary: false, temporary: false,
copySent: true, copySent: true,
email: ui.NewTextInput("", conf.Ui).Prompt("> "), email: ui.NewTextInput("", &conf.Ui).Prompt("> "),
fullName: ui.NewTextInput("", conf.Ui).Prompt("> "), fullName: ui.NewTextInput("", &conf.Ui).Prompt("> "),
imapPassword: ui.NewTextInput("", conf.Ui).Prompt("] ").Password(true), imapPassword: ui.NewTextInput("", &conf.Ui).Prompt("] ").Password(true),
imapServer: ui.NewTextInput("", conf.Ui).Prompt("> "), imapServer: ui.NewTextInput("", &conf.Ui).Prompt("> "),
imapStr: ui.NewText("imaps://", conf.Ui.GetStyle(config.STYLE_DEFAULT)), imapStr: ui.NewText("imaps://", conf.Ui.GetStyle(config.STYLE_DEFAULT)),
imapUsername: ui.NewTextInput("", conf.Ui).Prompt("> "), imapUsername: ui.NewTextInput("", &conf.Ui).Prompt("> "),
smtpPassword: ui.NewTextInput("", conf.Ui).Prompt("] ").Password(true), smtpPassword: ui.NewTextInput("", &conf.Ui).Prompt("] ").Password(true),
smtpServer: ui.NewTextInput("", conf.Ui).Prompt("> "), smtpServer: ui.NewTextInput("", &conf.Ui).Prompt("> "),
smtpStr: ui.NewText("smtps://", conf.Ui.GetStyle(config.STYLE_DEFAULT)), smtpStr: ui.NewText("smtps://", conf.Ui.GetStyle(config.STYLE_DEFAULT)),
smtpUsername: ui.NewTextInput("", conf.Ui).Prompt("> "), smtpUsername: ui.NewTextInput("", &conf.Ui).Prompt("> "),
} }
// Autofill some stuff for the user // Autofill some stuff for the user
@ -179,7 +179,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
At(7, 0) At(7, 0)
basics.AddChild(wizard.email). basics.AddChild(wizard.email).
At(8, 0) At(8, 0)
selector := NewSelector([]string{"Next"}, 0, conf.Ui). selector := NewSelector([]string{"Next"}, 0, &conf.Ui).
OnChoose(func(option string) { OnChoose(func(option string) {
email := wizard.email.String() email := wizard.email.String()
if strings.ContainsRune(email, '@') { if strings.ContainsRune(email, '@') {
@ -265,7 +265,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
"IMAP over SSL/TLS", "IMAP over SSL/TLS",
"IMAP with STARTTLS", "IMAP with STARTTLS",
"Insecure IMAP", "Insecure IMAP",
}, 0, conf.Ui).Chooser(true).OnSelect(func(option string) { }, 0, &conf.Ui).Chooser(true).OnSelect(func(option string) {
switch option { switch option {
case "IMAP over SSL/TLS": case "IMAP over SSL/TLS":
wizard.imapMode = IMAP_OVER_TLS wizard.imapMode = IMAP_OVER_TLS
@ -277,7 +277,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
wizard.imapUri() wizard.imapUri()
}) })
incoming.AddChild(imapMode).At(11, 0) incoming.AddChild(imapMode).At(11, 0)
selector = NewSelector([]string{"Previous", "Next"}, 1, conf.Ui). selector = NewSelector([]string{"Previous", "Next"}, 1, &conf.Ui).
OnChoose(wizard.advance) OnChoose(wizard.advance)
incoming.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(12, 0) incoming.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(12, 0)
incoming.AddChild(wizard.imapStr).At(13, 0) incoming.AddChild(wizard.imapStr).At(13, 0)
@ -347,7 +347,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
"SMTP over SSL/TLS", "SMTP over SSL/TLS",
"SMTP with STARTTLS", "SMTP with STARTTLS",
"Insecure SMTP", "Insecure SMTP",
}, 0, conf.Ui).Chooser(true).OnSelect(func(option string) { }, 0, &conf.Ui).Chooser(true).OnSelect(func(option string) {
switch option { switch option {
case "SMTP over SSL/TLS": case "SMTP over SSL/TLS":
wizard.smtpMode = SMTP_OVER_TLS wizard.smtpMode = SMTP_OVER_TLS
@ -359,7 +359,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
wizard.smtpUri() wizard.smtpUri()
}) })
outgoing.AddChild(smtpMode).At(11, 0) outgoing.AddChild(smtpMode).At(11, 0)
selector = NewSelector([]string{"Previous", "Next"}, 1, conf.Ui). selector = NewSelector([]string{"Previous", "Next"}, 1, &conf.Ui).
OnChoose(wizard.advance) OnChoose(wizard.advance)
outgoing.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(12, 0) outgoing.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(12, 0)
outgoing.AddChild(wizard.smtpStr).At(13, 0) outgoing.AddChild(wizard.smtpStr).At(13, 0)
@ -367,7 +367,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
outgoing.AddChild( outgoing.AddChild(
ui.NewText("Copy sent messages to 'Sent' folder?", ui.NewText("Copy sent messages to 'Sent' folder?",
conf.Ui.GetStyle(config.STYLE_HEADER))).At(15, 0) conf.Ui.GetStyle(config.STYLE_HEADER))).At(15, 0)
copySent := NewSelector([]string{"Yes", "No"}, 0, conf.Ui). copySent := NewSelector([]string{"Yes", "No"}, 0, &conf.Ui).
Chooser(true).OnChoose(func(option string) { Chooser(true).OnChoose(func(option string) {
switch option { switch option {
case "Yes": case "Yes":
@ -402,7 +402,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
"Previous", "Previous",
"Finish & open tutorial", "Finish & open tutorial",
"Finish", "Finish",
}, 1, conf.Ui).OnChoose(func(option string) { }, 1, &conf.Ui).OnChoose(func(option string) {
switch option { switch option {
case "Previous": case "Previous":
wizard.advance("Previous") wizard.advance("Previous")

View File

@ -36,7 +36,7 @@ type AccountView struct {
newConn bool // True if this is a first run after a new connection/reconnection newConn bool // True if this is a first run after a new connection/reconnection
} }
func (acct *AccountView) UiConfig() config.UIConfig { func (acct *AccountView) UiConfig() *config.UIConfig {
var folder string var folder string
if dirlist := acct.Directories(); dirlist != nil { if dirlist := acct.Directories(); dirlist != nil {
folder = dirlist.Selected() folder = dirlist.Selected()

View File

@ -95,7 +95,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
} else { } else {
aerc.accounts[acct.Name] = view aerc.accounts[acct.Name] = view
conf := view.UiConfig() conf := view.UiConfig()
tabs.Add(view, acct.Name, &conf) tabs.Add(view, acct.Name, conf)
} }
} }
@ -325,10 +325,10 @@ func (aerc *Aerc) account(d ui.Drawable) *AccountView {
return nil return nil
} }
func (aerc *Aerc) SelectedAccountUiConfig() config.UIConfig { func (aerc *Aerc) SelectedAccountUiConfig() *config.UIConfig {
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct == nil { if acct == nil {
return aerc.conf.Ui return &aerc.conf.Ui
} }
return acct.UiConfig() return acct.UiConfig()
} }
@ -349,7 +349,7 @@ func (aerc *Aerc) NewTab(clickable ui.Drawable, name string) *ui.Tab {
var uiConf *config.UIConfig = nil var uiConf *config.UIConfig = nil
if acct := aerc.account(clickable); acct != nil { if acct := aerc.account(clickable); acct != nil {
conf := acct.UiConfig() conf := acct.UiConfig()
uiConf = &conf uiConf = conf
} }
tab := aerc.tabs.Add(clickable, name, uiConf) tab := aerc.tabs.Add(clickable, name, uiConf)
aerc.tabs.Select(len(aerc.tabs.Tabs) - 1) aerc.tabs.Select(len(aerc.tabs.Tabs) - 1)

View File

@ -14,10 +14,10 @@ type AuthInfo struct {
ui.Invalidatable ui.Invalidatable
authdetails *auth.Details authdetails *auth.Details
showInfo bool showInfo bool
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func NewAuthInfo(auth *auth.Details, showInfo bool, uiConfig config.UIConfig) *AuthInfo { func NewAuthInfo(auth *auth.Details, showInfo bool, uiConfig *config.UIConfig) *AuthInfo {
return &AuthInfo{authdetails: auth, showInfo: showInfo, uiConfig: uiConfig} return &AuthInfo{authdetails: auth, showInfo: showInfo, uiConfig: uiConfig}
} }

View File

@ -284,7 +284,7 @@ func (c *Composer) Encrypt() bool {
func (c *Composer) updateCrypto() error { func (c *Composer) updateCrypto() error {
if c.crypto == nil { if c.crypto == nil {
uiConfig := c.acct.UiConfig() uiConfig := c.acct.UiConfig()
c.crypto = newCryptoStatus(&uiConfig) c.crypto = newCryptoStatus(uiConfig)
} }
var err error var err error
// Check if signKey is empty so we only run this once // Check if signKey is empty so we only run this once
@ -924,11 +924,11 @@ type headerEditor struct {
header *mail.Header header *mail.Header
focused bool focused bool
input *ui.TextInput input *ui.TextInput
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func newHeaderEditor(name string, h *mail.Header, func newHeaderEditor(name string, h *mail.Header,
uiConfig config.UIConfig) *headerEditor { uiConfig *config.UIConfig) *headerEditor {
he := &headerEditor{ he := &headerEditor{
input: ui.NewTextInput("", uiConfig), input: ui.NewTextInput("", uiConfig),
name: name, name: name,

View File

@ -78,7 +78,7 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
skipSelectCancel: cancel, skipSelectCancel: cancel,
} }
uiConf := dirlist.UiConfig() uiConf := dirlist.UiConfig()
dirlist.spinner = NewSpinner(&uiConf) dirlist.spinner = NewSpinner(uiConf)
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) { dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
dirlist.Invalidate() dirlist.Invalidate()
}) })
@ -91,7 +91,7 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
return dirlist return dirlist
} }
func (dirlist *DirectoryList) UiConfig() config.UIConfig { func (dirlist *DirectoryList) UiConfig() *config.UIConfig {
return dirlist.aercConf.GetUiConfig(map[config.ContextType]string{ return dirlist.aercConf.GetUiConfig(map[config.ContextType]string{
config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name, config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name,
config.UI_CONTEXT_FOLDER: dirlist.Selected(), config.UI_CONTEXT_FOLDER: dirlist.Selected(),

View File

@ -22,7 +22,7 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
tabcomplete func(cmd string) ([]string, string), tabcomplete func(cmd string) ([]string, string),
cmdHistory lib.History) *ExLine { cmdHistory lib.History) *ExLine {
input := ui.NewTextInput("", conf.Ui).Prompt(":").Set(cmd) input := ui.NewTextInput("", &conf.Ui).Prompt(":").Set(cmd)
if conf.Ui.CompletionPopovers { if conf.Ui.CompletionPopovers {
input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) input.TabComplete(tabcomplete, conf.Ui.CompletionDelay)
} }
@ -43,7 +43,7 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string), func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string),
tabcomplete func(cmd string) ([]string, string)) *ExLine { tabcomplete func(cmd string) ([]string, string)) *ExLine {
input := ui.NewTextInput("", conf.Ui).Prompt(prompt) input := ui.NewTextInput("", &conf.Ui).Prompt(prompt)
if conf.Ui.CompletionPopovers { if conf.Ui.CompletionPopovers {
input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) input.TabComplete(tabcomplete, conf.Ui.CompletionDelay)
} }

View File

@ -25,7 +25,7 @@ func NewGetPasswd(title string, prompt string, conf *config.AercConfig,
title: title, title: title,
prompt: prompt, prompt: prompt,
conf: conf, conf: conf,
input: ui.NewTextInput("", conf.Ui).Password(true).Prompt("Password: "), input: ui.NewTextInput("", &conf.Ui).Password(true).Prompt("Password: "),
} }
getpasswd.input.OnInvalidate(func(_ ui.Drawable) { getpasswd.input.OnInvalidate(func(_ ui.Drawable) {
getpasswd.Invalidate() getpasswd.Invalidate()

View File

@ -37,7 +37,7 @@ type MessageViewer struct {
grid *ui.Grid grid *ui.Grid
switcher *PartSwitcher switcher *PartSwitcher
msg lib.MessageView msg lib.MessageView
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
type PartSwitcher struct { type PartSwitcher struct {
@ -523,7 +523,7 @@ type PartViewer struct {
source io.Reader source io.Reader
term *Terminal term *Terminal
grid *ui.Grid grid *ui.Grid
uiConfig config.UIConfig uiConfig *config.UIConfig
links []string links []string
} }
@ -837,7 +837,7 @@ type HeaderView struct {
Name string Name string
Value string Value string
ValueField ui.Drawable ValueField ui.Drawable
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func (hv *HeaderView) Draw(ctx *ui.Context) { func (hv *HeaderView) Draw(ctx *ui.Context) {

View File

@ -14,10 +14,10 @@ import (
type PGPInfo struct { type PGPInfo struct {
ui.Invalidatable ui.Invalidatable
details *models.MessageDetails details *models.MessageDetails
uiConfig config.UIConfig uiConfig *config.UIConfig
} }
func NewPGPInfo(details *models.MessageDetails, uiConfig config.UIConfig) *PGPInfo { func NewPGPInfo(details *models.MessageDetails, uiConfig *config.UIConfig) *PGPInfo {
return &PGPInfo{details: details, uiConfig: uiConfig} return &PGPInfo{details: details, uiConfig: uiConfig}
} }

View File

@ -16,13 +16,13 @@ type Selector struct {
focused bool focused bool
focus int focus int
options []string options []string
uiConfig config.UIConfig uiConfig *config.UIConfig
onChoose func(option string) onChoose func(option string)
onSelect func(option string) onSelect func(option string)
} }
func NewSelector(options []string, focus int, uiConfig config.UIConfig) *Selector { func NewSelector(options []string, focus int, uiConfig *config.UIConfig) *Selector {
return &Selector{ return &Selector{
focus: focus, focus: focus,
options: options, options: options,
@ -171,12 +171,12 @@ type SelectorDialog struct {
callback func(string, error) callback func(string, error)
title string title string
prompt string prompt string
uiConfig config.UIConfig uiConfig *config.UIConfig
selector *Selector selector *Selector
} }
func NewSelectorDialog(title string, prompt string, options []string, focus int, func NewSelectorDialog(title string, prompt string, options []string, focus int,
uiConfig config.UIConfig, cb func(string, error)) *SelectorDialog { uiConfig *config.UIConfig, cb func(string, error)) *SelectorDialog {
sd := &SelectorDialog{ sd := &SelectorDialog{
callback: cb, callback: cb,
title: title, title: title,

View File

@ -108,7 +108,7 @@ func (status *StatusLine) Expire() {
status.stack = nil status.stack = nil
} }
func (status *StatusLine) uiConfig() config.UIConfig { func (status *StatusLine) uiConfig() *config.UIConfig {
return status.aerc.SelectedAccountUiConfig() return status.aerc.SelectedAccountUiConfig()
} }