diff options
author | Robin Jarry <robin@jarry.cc> | 2022-09-06 07:33:21 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-06 22:56:47 +0100 |
commit | 535300cfdbfc6e72fe9717c409fa64f072a1c581 (patch) | |
tree | dadcb1c1d88406134e532ab0f6cd87e54ff659d7 /config/columns.go | |
parent | 012be0192c88f4fcfd5ed559edff4ca7366eb351 (diff) | |
download | aerc-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/columns.go')
-rw-r--r-- | config/columns.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/config/columns.go b/config/columns.go index 659be2c3..b1c7191b 100644 --- a/config/columns.go +++ b/config/columns.go @@ -3,6 +3,7 @@ package config import ( "bytes" "fmt" + "reflect" "regexp" "strconv" "strings" @@ -118,3 +119,42 @@ func ParseColumnDefs(key *ini.Key, section *ini.Section) ([]*ColumnDef, error) { } return columns, nil } + +func ColumnDefsToIni(defs []*ColumnDef, keyName string) string { + var s strings.Builder + var cols []string + templates := make(map[string]string) + + for _, def := range defs { + col := def.Name + switch { + case def.Flags.Has(ALIGN_LEFT): + col += "<" + case def.Flags.Has(ALIGN_CENTER): + col += ":" + case def.Flags.Has(ALIGN_RIGHT): + col += ">" + } + switch { + case def.Flags.Has(WIDTH_FIT): + col += "=" + case def.Flags.Has(WIDTH_AUTO): + col += "*" + case def.Flags.Has(WIDTH_FRACTION): + col += fmt.Sprintf("%.0f%%", def.Width*100) + default: + col += fmt.Sprintf("%.0f", def.Width) + } + cols = append(cols, col) + tree := reflect.ValueOf(def.Template.Tree) + text := tree.Elem().FieldByName("text").String() + templates[fmt.Sprintf("column-%s", def.Name)] = text + } + + s.WriteString(fmt.Sprintf("%s = %s\n", keyName, strings.Join(cols, ","))) + for name, text := range templates { + s.WriteString(fmt.Sprintf("%s = %s\n", name, text)) + } + + return s.String() +} |