Skip to content

Commit ab78a79

Browse files
tnk4oncgwalters
authored andcommitted
fix: Use unicode-width for accurate display width calculation
- status.rs: Use UnicodeWidthStr::width() for correct display alignment - container.rs: Use as_bytes().len() for hex string length verification - Add unicode-width dependency (already a transitive dep via comfy-table) Assisted-by: Cursor (Auto) Signed-off-by: Shion Tanaka <[email protected]>
1 parent 4cb64bb commit ab78a79

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

crates/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ xshell = { workspace = true, optional = true }
6060
anstyle = "1.0.6"
6161
comfy-table = "7.1.1"
6262
liboverdrop = "0.1.0"
63+
unicode-width = "0.2"
6364
libsystemd = "0.7"
6465
linkme = "0.3"
6566
nom = "8.0.0"

crates/lib/src/status.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ostree_ext::oci_spec;
1515
use ostree_ext::oci_spec::image::Digest;
1616
use ostree_ext::oci_spec::image::ImageConfiguration;
1717
use ostree_ext::sysroot::SysrootLock;
18+
use unicode_width::UnicodeWidthStr;
1819

1920
use ostree_ext::ostree;
2021

@@ -832,7 +833,11 @@ fn container_inspect_print_human(
832833
rows.push(("Kargs", kargs));
833834

834835
// Find the max label width for right-alignment
835-
let max_label_len = rows.iter().map(|(label, _)| label.len()).max().unwrap_or(0);
836+
let max_label_len = rows
837+
.iter()
838+
.map(|(label, _)| label.width())
839+
.max()
840+
.unwrap_or(0);
836841

837842
for (label, value) in rows {
838843
write_row_name(&mut out, label, max_label_len)?;

crates/tests-integration/src/container.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ pub(crate) fn test_compute_composefs_digest() -> Result<()> {
201201

202202
// Verify it's a valid hex string of expected length (SHA-512 = 128 hex chars)
203203
assert_eq!(
204-
digest.len(),
204+
digest.as_bytes().len(),
205205
128,
206206
"Expected 512-bit hex digest, got length {}",
207-
digest.len()
207+
digest.as_bytes().len()
208208
);
209209
assert!(
210210
digest.chars().all(|c| c.is_ascii_hexdigit()),

0 commit comments

Comments
 (0)