~sircmpwn/aerc

Selector Widget: Allow wrapping v1 PROPOSED

Zach DeCook
Zach DeCook: 2
 Selector Widget: Allow wrapping
 New account wizard: Allow creating account on small screens

 3 files changed, 28 insertions(+), 46 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/22709/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH 1/2] Selector Widget: Allow wrapping Export this patch

Zach DeCook
---
 widgets/account-wizard.go |  2 +-
 widgets/selector.go       | 10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index d8e2eb0..00ce59b 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -223,7 +223,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection mode (label)
		{ui.SIZE_EXACT, ui.Const(2)}, // (input)
		{ui.SIZE_EXACT, ui.Const(3)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection string
		{ui.SIZE_WEIGHT, ui.Const(1)},
diff --git a/widgets/selector.go b/widgets/selector.go
index 196601b..a0cf598 100644
--- a/widgets/selector.go
+++ b/widgets/selector.go
@@ -40,6 +40,7 @@ func (sel *Selector) Draw(ctx *ui.Context) {
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
		sel.uiConfig.GetStyle(config.STYLE_SELECTOR_DEFAULT))
	x := 2
	y := 0
	for i, option := range sel.options {
		style := sel.uiConfig.GetStyle(config.STYLE_SELECTOR_DEFAULT)
		if sel.focus == i {
@@ -49,8 +50,13 @@ func (sel *Selector) Draw(ctx *ui.Context) {
				style = sel.uiConfig.GetStyle(config.STYLE_SELECTOR_CHOOSER)
			}
		}
		x += ctx.Printf(x, 1, style, "[%s]", option)
		x += 5
		if x > 2 && x + len(option) >= ctx.Width() {
			x = 2
			// Warning: context may not be tall enough to wrap.
			y += 1
		}
		x += ctx.Printf(x, y, style, "[%s]", option)
		x += 3
	}
}

-- 
2.31.1
Hi,
Thanks for the patches, appreciated.

On Fri, May 14, 2021 at 09:44:41PM -0400, Zach DeCook wrote:

[PATCH 2/2] New account wizard: Allow creating account on small screens Export this patch

Zach DeCook
---
 widgets/account-wizard.go | 62 ++++++++++++---------------------------
 1 file changed, 19 insertions(+), 43 deletions(-)

diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 00ce59b..30f19ee 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -215,16 +215,12 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		{ui.SIZE_EXACT, ui.Const(3)}, // Introduction
		{ui.SIZE_EXACT, ui.Const(1)}, // Username (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Password (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Server (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection mode (label)
		{ui.SIZE_EXACT, ui.Const(3)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection string
		{ui.SIZE_WEIGHT, ui.Const(1)},
	}).Columns([]ui.GridSpec{
@@ -238,29 +234,23 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		At(1, 0)
	incoming.AddChild(wizard.imapUsername).
		At(2, 0)
	incoming.AddChild(ui.NewFill(' ')).
		At(3, 0)
	incoming.AddChild(
		ui.NewText("Password",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(4, 0)
		At(3, 0)
	incoming.AddChild(wizard.imapPassword).
		At(5, 0)
	incoming.AddChild(ui.NewFill(' ')).
		At(6, 0)
		At(4, 0)
	incoming.AddChild(
		ui.NewText("Server address "+
			"(e.g. 'mail.example.org' or 'mail.example.org:1313')",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(7, 0)
		At(5, 0)
	incoming.AddChild(wizard.imapServer).
		At(8, 0)
	incoming.AddChild(ui.NewFill(' ')).
		At(9, 0)
		At(6, 0)
	incoming.AddChild(
		ui.NewText("Connection mode",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(10, 0)
		At(7, 0)
	imapMode := NewSelector([]string{
		"IMAP over SSL/TLS",
		"IMAP with STARTTLS",
@@ -276,12 +266,11 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		}
		wizard.imapUri()
	})
	incoming.AddChild(imapMode).At(11, 0)
	incoming.AddChild(imapMode).At(8, 0)
	selector = NewSelector([]string{"Previous", "Next"}, 1, conf.Ui).
		OnChoose(wizard.advance)
	incoming.AddChild(ui.NewFill(' ')).At(12, 0)
	incoming.AddChild(wizard.imapStr).At(13, 0)
	incoming.AddChild(selector).At(14, 0)
	incoming.AddChild(wizard.imapStr).At(9, 0)
	incoming.AddChild(selector).At(10, 0)
	wizard.incoming = []ui.Interactive{
		wizard.imapUsername, wizard.imapPassword, wizard.imapServer,
		imapMode, selector,
@@ -294,18 +283,13 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		{ui.SIZE_EXACT, ui.Const(3)}, // Introduction
		{ui.SIZE_EXACT, ui.Const(1)}, // Username (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Password (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Server (label)
		{ui.SIZE_EXACT, ui.Const(1)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection mode (label)
		{ui.SIZE_EXACT, ui.Const(2)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(3)}, // (input)
		{ui.SIZE_EXACT, ui.Const(1)}, // Connection string
		{ui.SIZE_EXACT, ui.Const(1)}, // Padding
		{ui.SIZE_EXACT, ui.Const(1)}, // Copy to sent (label)
		{ui.SIZE_EXACT, ui.Const(2)}, // (input)
		{ui.SIZE_WEIGHT, ui.Const(1)},
@@ -320,29 +304,23 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		At(1, 0)
	outgoing.AddChild(wizard.smtpUsername).
		At(2, 0)
	outgoing.AddChild(ui.NewFill(' ')).
		At(3, 0)
	outgoing.AddChild(
		ui.NewText("Password",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(4, 0)
		At(3, 0)
	outgoing.AddChild(wizard.smtpPassword).
		At(5, 0)
	outgoing.AddChild(ui.NewFill(' ')).
		At(6, 0)
		At(4, 0)
	outgoing.AddChild(
		ui.NewText("Server address "+
			"(e.g. 'mail.example.org' or 'mail.example.org:1313')",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(7, 0)
		At(5, 0)
	outgoing.AddChild(wizard.smtpServer).
		At(8, 0)
	outgoing.AddChild(ui.NewFill(' ')).
		At(9, 0)
		At(6, 0)
	outgoing.AddChild(
		ui.NewText("Connection mode",
			conf.Ui.GetStyle(config.STYLE_HEADER))).
		At(10, 0)
		At(7, 0)
	smtpMode := NewSelector([]string{
		"SMTP over SSL/TLS",
		"SMTP with STARTTLS",
@@ -358,15 +336,13 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
		}
		wizard.smtpUri()
	})
	outgoing.AddChild(smtpMode).At(11, 0)
	outgoing.AddChild(smtpMode).At(8, 0)
	selector = NewSelector([]string{"Previous", "Next"}, 1, conf.Ui).
		OnChoose(wizard.advance)
	outgoing.AddChild(ui.NewFill(' ')).At(12, 0)
	outgoing.AddChild(wizard.smtpStr).At(13, 0)
	outgoing.AddChild(ui.NewFill(' ')).At(14, 0)
	outgoing.AddChild(wizard.smtpStr).At(9, 0)
	outgoing.AddChild(
		ui.NewText("Copy sent messages to 'Sent' folder?",
			conf.Ui.GetStyle(config.STYLE_HEADER))).At(15, 0)
			conf.Ui.GetStyle(config.STYLE_HEADER))).At(10, 0)
	copySent := NewSelector([]string{"Yes", "No"}, 0, conf.Ui).
		Chooser(true).OnChoose(func(option string) {
		switch option {
@@ -376,8 +352,8 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
			wizard.copySent = false
		}
	})
	outgoing.AddChild(copySent).At(16, 0)
	outgoing.AddChild(selector).At(17, 0)
	outgoing.AddChild(copySent).At(11, 0)
	outgoing.AddChild(selector).At(12, 0)
	wizard.outgoing = []ui.Interactive{
		wizard.smtpUsername, wizard.smtpPassword, wizard.smtpServer,
		smtpMode, copySent, selector,
-- 
2.31.1