From 9cfa2ca258d4e2a292a8f33fc4c6875257049039 Mon Sep 17 00:00:00 2001 From: Shion Tanaka Date: Sat, 10 Jan 2026 00:49:04 +0900 Subject: [PATCH] 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 --- crates/lib/Cargo.toml | 1 + crates/lib/src/status.rs | 7 ++++++- crates/tests-integration/src/container.rs | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index aa033ed3d..0c6017f04 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -60,6 +60,7 @@ xshell = { workspace = true, optional = true } anstyle = "1.0.6" comfy-table = "7.1.1" liboverdrop = "0.1.0" +unicode-width = "0.2" libsystemd = "0.7" linkme = "0.3" nom = "8.0.0" diff --git a/crates/lib/src/status.rs b/crates/lib/src/status.rs index 20bf11e6c..f0ce7cc94 100644 --- a/crates/lib/src/status.rs +++ b/crates/lib/src/status.rs @@ -15,6 +15,7 @@ use ostree_ext::oci_spec; use ostree_ext::oci_spec::image::Digest; use ostree_ext::oci_spec::image::ImageConfiguration; use ostree_ext::sysroot::SysrootLock; +use unicode_width::UnicodeWidthStr; use ostree_ext::ostree; @@ -832,7 +833,11 @@ fn container_inspect_print_human( rows.push(("Kargs", kargs)); // Find the max label width for right-alignment - let max_label_len = rows.iter().map(|(label, _)| label.len()).max().unwrap_or(0); + let max_label_len = rows + .iter() + .map(|(label, _)| label.width()) + .max() + .unwrap_or(0); for (label, value) in rows { write_row_name(&mut out, label, max_label_len)?; diff --git a/crates/tests-integration/src/container.rs b/crates/tests-integration/src/container.rs index 005664d43..2c8ab9b89 100644 --- a/crates/tests-integration/src/container.rs +++ b/crates/tests-integration/src/container.rs @@ -201,10 +201,10 @@ pub(crate) fn test_compute_composefs_digest() -> Result<()> { // Verify it's a valid hex string of expected length (SHA-512 = 128 hex chars) assert_eq!( - digest.len(), + digest.as_bytes().len(), 128, "Expected 512-bit hex digest, got length {}", - digest.len() + digest.as_bytes().len() ); assert!( digest.chars().all(|c| c.is_ascii_hexdigit()),