aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinghao Wu <xdavidwuph@gmail.com>2022-07-27 20:08:03 +0800
committerRobin Jarry <robin@jarry.cc>2022-07-30 17:58:26 +0200
commitb8ef8d2628e2b307864aee1f61ab4036d0473b33 (patch)
treeb29ffeb2d13f53ddd0adb1c3bc3e615e20f84440
parent3304ea18bac8e5faae383c1dfc16f6f910e2c53e (diff)
downloadaerc-b8ef8d2628e2b307864aee1f61ab4036d0473b33.tar.gz
index: workaround for wide character printing
This is a workaround for https://todo.sr.ht/~rjarry/aerc/22, by injecting zero-width spaces in front of wide characters to make up width calculation in fmt.Sprintf. With this applied, columns will still be misaligned a little only if they are left with trailing zero-width spaces when cut. It is better than a large offset caused by each wide characters in the column. References: https://todo.sr.ht/~rjarry/aerc/22 Signed-off-by: Pinghao Wu <xdavidwuph@gmail.com> Acked-by: Koni Marti <koni.marti@gmail.com>
-rw-r--r--lib/format/format.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index ca90ac4a..cc9716dd 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -10,6 +10,7 @@ import (
"git.sr.ht/~rjarry/aerc/models"
"github.com/emersion/go-message/mail"
+ "github.com/mattn/go-runewidth"
)
// AddressForHumans formats the address. If the address's name
@@ -365,6 +366,22 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
i = ni + 1
}
+ const zeroWidthSpace rune = '\u200b'
+ for i, val := range args {
+ if s, ok := val.(string); ok {
+ var out strings.Builder
+ for _, r := range s {
+ w := runewidth.RuneWidth(r)
+ for w > 1 {
+ out.WriteRune(zeroWidthSpace)
+ w -= 1
+ }
+ out.WriteRune(r)
+ }
+ args[i] = out.String()
+ }
+ }
+
return string(retval), args, nil
handle_end_error: