aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-11-11 17:50:39 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-12 12:53:11 +0100
commit485a2c52f6b64c45b2f4e74cdbf7fee961fcdcf0 (patch)
tree96be0c603d9ea7636c841a79aee89c579bed466a
parent213d65d00fb963c42cb3fa2b9b21c1613ec316a2 (diff)
downloadaerc-485a2c52f6b64c45b2f4e74cdbf7fee961fcdcf0.tar.gz
completion: hide quotes from choices
When completion choices are surrounded by quotes to make sure that they will be interpreted as a single argument, hide them before presenting the choices to the user. It makes the UI cluttered and harder to read. The completion values remain identical, the quotes will be inserted when the user accepts one choice. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
-rw-r--r--lib/ui/textinput.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index d1d46045..9886da9f 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -408,10 +408,17 @@ type completions struct {
uiConfig *config.UIConfig
}
+func unquote(s string) string {
+ if strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'") {
+ s = strings.ReplaceAll(s[1:len(s)-1], `'"'"'`, "'")
+ }
+ return s
+}
+
func maxLen(ss []string) int {
max := 0
for _, s := range ss {
- l := runewidth.StringWidth(s)
+ l := runewidth.StringWidth(unquote(s))
if l > max {
max = l
}
@@ -443,9 +450,9 @@ func (c *completions) Draw(ctx *Context) {
}
if c.idx == idx {
ctx.Fill(0, idx-startIdx, ctx.Width(), 1, ' ', sel)
- ctx.Printf(0, idx-startIdx, sel, " %s ", opt)
+ ctx.Printf(0, idx-startIdx, sel, " %s ", unquote(opt))
} else {
- ctx.Printf(0, idx-startIdx, bg, " %s ", opt)
+ ctx.Printf(0, idx-startIdx, bg, " %s ", unquote(opt))
}
}