mirror of
https://github.com/restic/restic.git
synced 2026-07-16 12:14:54 +00:00
Use character display width for table padding
Using len(...) for table cell padding produced wrong results for unicode chracters leading to misaligned tables. Implementation changed to take the actual terminal display width into consideration.
This commit is contained in:
@@ -84,3 +84,21 @@ func TestParseBytesInvalid(t *testing.T) {
|
||||
test.Equals(t, int64(0), v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminalDisplayWidth(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
input string
|
||||
want int
|
||||
}{
|
||||
{"foo", 3},
|
||||
{"aéb", 3},
|
||||
{"ab", 3},
|
||||
{"a’b", 3},
|
||||
{"aあb", 4},
|
||||
} {
|
||||
if got := TerminalDisplayWidth(c.input); got != c.want {
|
||||
t.Errorf("wrong display width for '%s', want %d, got %d", c.input, c.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user