From 6314e2dc67418141b12081bde846091e5e160702 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 12 Feb 2024 06:26:27 -0600 Subject: vaxis: update to v0.7.2 and update ansi parser Update Vaxis to v0.7.2 to gain performance improvements and StyledString parsing. The Vaxis parser fully accounts for the terminal's capability to display wide characters. Use the Vaxis StyledString parser to parse and style ansi-encoded strings. Remove unneeded code and tests. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/ui/table.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'lib/ui/table.go') diff --git a/lib/ui/table.go b/lib/ui/table.go index ceb01c78..3f5fc4b3 100644 --- a/lib/ui/table.go +++ b/lib/ui/table.go @@ -5,7 +5,6 @@ import ( "regexp" "git.sr.ht/~rjarry/aerc/config" - "git.sr.ht/~rjarry/aerc/lib/parse" "git.sr.ht/~rockorager/vaxis" "github.com/mattn/go-runewidth" ) @@ -93,7 +92,7 @@ func (t *Table) computeWidths(width int) { if t.autoFitWidths { for _, row := range t.Rows { for c := range t.Columns { - buf := parse.ParseANSI(row.Cells[c]) + buf := StyledString(row.Cells[c]) if buf.Len() > contentMaxWidths[c] { contentMaxWidths[c] = buf.Len() } @@ -160,32 +159,35 @@ var metaCharsRegexp = regexp.MustCompile(`[\t\r\f\n\v]`) func (col *Column) alignCell(cell string) string { cell = metaCharsRegexp.ReplaceAllString(cell, " ") - buf := parse.ParseANSI(cell) + buf := StyledString(cell) width := buf.Len() switch { case col.Def.Flags.Has(config.ALIGN_LEFT): if width < col.Width { - buf.PadRight(col.Width, ' ', vaxis.Style{}) - cell = buf.String() + PadRight(buf, col.Width) + cell = buf.Encode() } else if width > col.Width { - cell = buf.Truncate(col.Width, '…') + Truncate(buf, col.Width) + cell = buf.Encode() } case col.Def.Flags.Has(config.ALIGN_CENTER): if width < col.Width { pad := col.Width - width - buf.PadLeft(col.Width-(pad/2), ' ', vaxis.Style{}) - buf.PadRight(col.Width, ' ', vaxis.Style{}) - cell = buf.String() + PadLeft(buf, col.Width-(pad/2)) + PadRight(buf, col.Width) + cell = buf.Encode() } else if width > col.Width { - cell = buf.Truncate(col.Width, '…') + Truncate(buf, col.Width) + cell = buf.Encode() } case col.Def.Flags.Has(config.ALIGN_RIGHT): if width < col.Width { - buf.PadLeft(col.Width, ' ', vaxis.Style{}) - cell = buf.String() + PadLeft(buf, col.Width) + cell = buf.Encode() } else if width > col.Width { - cell = buf.TruncateHead(col.Width, '…') + TruncateHead(buf, col.Width) + cell = buf.Encode() } } @@ -209,9 +211,9 @@ func (t *Table) Draw(ctx *Context) { cell := col.alignCell(row.Cells[c]) style := t.GetRowStyle(t, r) - buf := parse.ParseANSI(cell) - buf.ApplyAttrs(style) - cell = buf.String() + buf := StyledString(cell) + ApplyAttrs(buf, style) + cell = buf.Encode() ctx.Printf(col.Offset, r, style, "%s%s", cell, col.Separator) } } -- cgit