~sircmpwn/aerc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH 1/2] Selector Widget: Allow wrapping

Zach DeCook <zdecook@ccel.org>
Details
Message ID
<20210515014442.72109-1-zdecook@ccel.org>
DKIM signature
missing
Download raw message
Patch: +9 -3
---
 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

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

Zach DeCook <zdecook@ccel.org>
Details
Message ID
<20210515014442.72109-2-zdecook@ccel.org>
In-Reply-To
<20210515014442.72109-1-zdecook@ccel.org> (view parent)
DKIM signature
missing
Download raw message
Patch: +19 -43
---
 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
Details
Message ID
<20210516101944.wd3dj5bu4syud76n@feather>
In-Reply-To
<20210515014442.72109-1-zdecook@ccel.org> (view parent)
DKIM signature
missing
Download raw message
Hi,
Thanks for the patches, appreciated.

On Fri, May 14, 2021 at 09:44:41PM -0400, Zach DeCook wrote:
> @@ -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

Don't do that please, you know the height of the context, don't just blindly
try to write out of bounds. That would not be an improvement.

For your second patch, while I see the appeal of reducing the padding on small
screens, it looks horrible on a normal sized terminal (by some definition of normal).
So I don't think we should do this unconditionally either.
Maybe check the height and add padding or not depending on the screen size?

What do you think?

Cheers,
Reto
Reply to thread Export thread (mbox)