diff options
author | Greg Anders <greg@gpanders.com> | 2019-11-15 13:28:34 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-11-17 13:19:13 -0500 |
commit | 4bdef7d8609aa2d382fa74018e28ccb176276615 (patch) | |
tree | ef22e1ef17c3247de6531715c7502a3a3d313867 /widgets/account-wizard.go | |
parent | 809083f8438401e2ee1d2d14712677f55eb4e4ef (diff) |
Add UI options to save/pipe messages with unsupported mimetypes
Adds a message indicating the user's ability to :save or :pipe a message
with an unsupported mimetype and also adds a selector widget (similar to
the tutorial).
The selector widget was previously defined in the account wizard module,
so this commit breaks it out into its own module to allow for re-use.
Further, modify the BeginExLine() function to take an argument that
pre-populates the command line, allowing functions to initiate an ex
command without executing it.
Closes #95.
Diffstat (limited to 'widgets/account-wizard.go')
-rw-r--r-- | widgets/account-wizard.go | 110 |
1 files changed, 7 insertions, 103 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 904013f..d7b46b9 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -177,7 +177,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { At(7, 0) basics.AddChild(wizard.email). At(8, 0) - selecter := newSelecter([]string{"Next"}, 0). + selecter := NewSelecter([]string{"Next"}, 0). OnChoose(func(option string) { email := wizard.email.String() if strings.ContainsRune(email, '@') { @@ -254,7 +254,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { incoming.AddChild( ui.NewText("Connection mode").Bold(true)). At(10, 0) - imapMode := newSelecter([]string{ + imapMode := NewSelecter([]string{ "IMAP over SSL/TLS", "IMAP with STARTTLS", "Insecure IMAP", @@ -270,7 +270,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard.imapUri() }) incoming.AddChild(imapMode).At(11, 0) - selecter = newSelecter([]string{"Previous", "Next"}, 1). + selecter = NewSelecter([]string{"Previous", "Next"}, 1). OnChoose(wizard.advance) incoming.AddChild(ui.NewFill(' ')).At(12, 0) incoming.AddChild(wizard.imapStr).At(13, 0) @@ -331,7 +331,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { outgoing.AddChild( ui.NewText("Connection mode").Bold(true)). At(10, 0) - smtpMode := newSelecter([]string{ + smtpMode := NewSelecter([]string{ "SMTP over SSL/TLS", "SMTP with STARTTLS", "Insecure SMTP", @@ -347,7 +347,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard.smtpUri() }) outgoing.AddChild(smtpMode).At(11, 0) - selecter = newSelecter([]string{"Previous", "Next"}, 1). + selecter = NewSelecter([]string{"Previous", "Next"}, 1). OnChoose(wizard.advance) outgoing.AddChild(ui.NewFill(' ')).At(12, 0) outgoing.AddChild(wizard.smtpStr).At(13, 0) @@ -355,7 +355,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { outgoing.AddChild( ui.NewText("Copy sent messages to 'Sent' folder?").Bold(true)). At(15, 0) - copySent := newSelecter([]string{"Yes", "No"}, 0). + copySent := NewSelecter([]string{"Yes", "No"}, 0). Chooser(true).OnChoose(func(option string) { switch option { case "Yes": @@ -385,7 +385,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { "You can go back and double check your settings, or choose 'Finish' to\n" + "save your settings to accounts.conf.\n\n" + "To add another account in the future, run ':new-account'.")) - selecter = newSelecter([]string{ + selecter = NewSelecter([]string{ "Previous", "Finish & open tutorial", "Finish", @@ -716,102 +716,6 @@ func (wizard *AccountWizard) Event(event tcell.Event) bool { return false } -type selecter struct { - ui.Invalidatable - chooser bool - focused bool - focus int - options []string - - onChoose func(option string) - onSelect func(option string) -} - -func newSelecter(options []string, focus int) *selecter { - return &selecter{ - focus: focus, - options: options, - } -} - -func (sel *selecter) Chooser(chooser bool) *selecter { - sel.chooser = chooser - return sel -} - -func (sel *selecter) Invalidate() { - sel.DoInvalidate(sel) -} - -func (sel *selecter) Draw(ctx *ui.Context) { - ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) - x := 2 - for i, option := range sel.options { - style := tcell.StyleDefault - if sel.focus == i { - if sel.focused { - style = style.Reverse(true) - } else if sel.chooser { - style = style.Bold(true) - } - } - x += ctx.Printf(x, 1, style, "[%s]", option) - x += 5 - } -} - -func (sel *selecter) OnChoose(fn func(option string)) *selecter { - sel.onChoose = fn - return sel -} - -func (sel *selecter) OnSelect(fn func(option string)) *selecter { - sel.onSelect = fn - return sel -} - -func (sel *selecter) Selected() string { - return sel.options[sel.focus] -} - -func (sel *selecter) Focus(focus bool) { - sel.focused = focus - sel.Invalidate() -} - -func (sel *selecter) Event(event tcell.Event) bool { - switch event := event.(type) { - case *tcell.EventKey: - switch event.Key() { - case tcell.KeyCtrlH: - fallthrough - case tcell.KeyLeft: - if sel.focus > 0 { - sel.focus-- - sel.Invalidate() - } - if sel.onSelect != nil { - sel.onSelect(sel.Selected()) - } - case tcell.KeyCtrlL: - fallthrough - case tcell.KeyRight: - if sel.focus < len(sel.options)-1 { - sel.focus++ - sel.Invalidate() - } - if sel.onSelect != nil { - sel.onSelect(sel.Selected()) - } - case tcell.KeyEnter: - if sel.onChoose != nil { - sel.onChoose(sel.Selected()) - } - } - } - return false -} - func getSRV(host string, services []string) (string, string) { var hostport, srv string for _, srv = range services { |