aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-04 01:37:18 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-04 18:03:28 +0100
commita603d3de038ae75abddd33078a1c8c56614eaf0d (patch)
treec69796b042f4669df141793968bfe637b92317ef /lib/ui
parentd5e47e300a42ed64c17e4b391b77234e22c9f915 (diff)
downloadaerc-a603d3de038ae75abddd33078a1c8c56614eaf0d.tar.gz
table: fix center padding
When a column has ALIGN_CENTER and the number of white space character of padding is not a multiple of two, the last cell(character) is not padded and that can cause coloring glitches. Make sure to pad all the way. Fixes: 49de9b09cacc ("ui: parse strings for ansi styles") Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/table.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/ui/table.go b/lib/ui/table.go
index 704dd2be..9cb96bd9 100644
--- a/lib/ui/table.go
+++ b/lib/ui/table.go
@@ -166,29 +166,23 @@ func (col *Column) alignCell(cell string) string {
switch {
case col.Def.Flags.Has(config.ALIGN_LEFT):
if width < col.Width {
- for i := 0; i < (col.Width - width); i += 1 {
- buf.Write(' ', tcell.StyleDefault)
- }
+ buf.PadRight(col.Width, ' ', tcell.StyleDefault)
cell = buf.String()
} else if width > col.Width {
cell = buf.Truncate(col.Width, '…')
}
case col.Def.Flags.Has(config.ALIGN_CENTER):
if width < col.Width {
- pad := (col.Width - width) / 2
- for i := 0; i < pad; i += 1 {
- buf.Prepend(' ', tcell.StyleDefault)
- buf.Write(' ', tcell.StyleDefault)
- }
+ pad := col.Width - width
+ buf.PadLeft(col.Width-(pad/2), ' ', tcell.StyleDefault)
+ buf.PadRight(col.Width, ' ', tcell.StyleDefault)
cell = buf.String()
} else if width > col.Width {
cell = buf.Truncate(col.Width, '…')
}
case col.Def.Flags.Has(config.ALIGN_RIGHT):
if width < col.Width {
- for i := 0; i < (col.Width - width); i += 1 {
- buf.Prepend(' ', tcell.StyleDefault)
- }
+ buf.PadLeft(col.Width, ' ', tcell.StyleDefault)
cell = buf.String()
} else if width > col.Width {
cell = buf.TruncateHead(col.Width, '…')