aboutsummaryrefslogtreecommitdiffstats
path: root/config/ui_test.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-09-06 07:33:21 +0200
committerRobin Jarry <robin@jarry.cc>2023-01-06 22:56:47 +0100
commit535300cfdbfc6e72fe9717c409fa64f072a1c581 (patch)
treedadcb1c1d88406134e532ab0f6cd87e54ff659d7 /config/ui_test.go
parent012be0192c88f4fcfd5ed559edff4ca7366eb351 (diff)
downloadaerc-535300cfdbfc6e72fe9717c409fa64f072a1c581.tar.gz
config: add columns based index format
The index-format option comes from mutt and is neither user friendly, nor intuitive. Introduce a new way of configuring the message list contents. Replace index-format with multiple settings to make everything more intuitive. Reuse the table widget added in the previous commit. index-columns Comma-separated list of column names followed by optional alignment and width specifiers. column-separator String separator between columns. column-$name One setting for every name defined in index-columns. This supports golang text/template syntax and allows access to the same message information than before and much more. When index-format is still defined in aerc.conf (which will most likely happen when users will update after this patch), convert it to the new index-columns + column-$name and column-separator system and a warning is displayed on startup so that users are aware that they need to update their config. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'config/ui_test.go')
-rw-r--r--config/ui_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/config/ui_test.go b/config/ui_test.go
new file mode 100644
index 00000000..c5eb6031
--- /dev/null
+++ b/config/ui_test.go
@@ -0,0 +1,46 @@
+package config
+
+import (
+ "bytes"
+ "testing"
+
+ "git.sr.ht/~rjarry/aerc/lib/templates"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestConvertIndexFormat(t *testing.T) {
+ columns, err := convertIndexFormat("%-20.20D %-17.17n %Z %s")
+ if err != nil {
+ t.Fatal(err)
+ }
+ assert.Len(t, columns, 4)
+
+ data := templates.DummyData()
+ var buf bytes.Buffer
+
+ assert.Equal(t, "date", columns[0].Name)
+ assert.Equal(t, 20.0, columns[0].Width)
+ assert.Equal(t, ALIGN_LEFT|WIDTH_EXACT, columns[0].Flags)
+ assert.Nil(t, columns[0].Template.Execute(&buf, data))
+
+ buf.Reset()
+ assert.Equal(t, "name", columns[1].Name)
+ assert.Equal(t, 17.0, columns[1].Width)
+ assert.Equal(t, ALIGN_LEFT|WIDTH_EXACT, columns[1].Flags)
+ assert.Nil(t, columns[1].Template.Execute(&buf, data))
+ assert.Equal(t, "John Doe", buf.String())
+
+ buf.Reset()
+ assert.Equal(t, "flags", columns[2].Name)
+ assert.Equal(t, 4.0, columns[2].Width)
+ assert.Equal(t, ALIGN_RIGHT|WIDTH_EXACT, columns[2].Flags)
+ assert.Nil(t, columns[2].Template.Execute(&buf, data))
+ assert.Equal(t, "O!*", buf.String())
+
+ buf.Reset()
+ assert.Equal(t, "subject", columns[3].Name)
+ assert.Equal(t, 0.0, columns[3].Width)
+ assert.Equal(t, ALIGN_LEFT|WIDTH_AUTO, columns[3].Flags)
+ assert.Nil(t, columns[3].Template.Execute(&buf, data))
+ assert.Equal(t, "[PATCH aerc 2/3] foo: baz bar buz", buf.String())
+}