fix(cli): pad table columns by display width
Byte-length padding misaligned columns for non-ASCII names; widths and padding now use display width via ratatui's Span.
This commit is contained in:
1 parent
0db8421caf
commit
7a6145342d
2 files changed
+39
-7
No files matched your search
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::{format_datetime, render_table};
|
||||
use chrono::{TimeZone, Utc};
|
||||
|
||||
@@ -18,6 +21,24 @@ fn render_table_aligns_columns() {
|
||||
assert_eq!(lines[3], "Longer Name off ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_table_aligns_multibyte_names() {
|
||||
// padding must use display width, not byte length: "Öctra" is 6 bytes
|
||||
// but 5 columns wide, and byte-based padding pushed every later column.
|
||||
let rendered = render_table(
|
||||
&["Name", "State"],
|
||||
&[
|
||||
vec!["Öctra".to_string(), "enabled".to_string()],
|
||||
vec!["Longer Name".to_string(), "off".to_string()],
|
||||
],
|
||||
);
|
||||
|
||||
let lines: Vec<&str> = rendered.lines().collect();
|
||||
assert_eq!(lines[0], "Name State ");
|
||||
assert_eq!(lines[2], "Öctra enabled");
|
||||
assert_eq!(lines[3], "Longer Name off ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_datetime_consistently() {
|
||||
let dt = Utc.with_ymd_and_hms(2024, 1, 2, 3, 4, 5).unwrap();
|
||||
|
||||
Reference in new issue
Block a user