diff --git a/Cargo.lock b/Cargo.lock index 01c33dc..d220ce7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,7 +249,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "unicode-width", + "unicode-width 0.1.14", "windows-sys 0.52.0", ] @@ -401,6 +401,7 @@ dependencies = [ "tracing-attributes", "tracing-subscriber", "typed-path", + "unicode-width 0.2.0", "xxhash-rust", "zerocopy", ] @@ -554,7 +555,7 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" dependencies = [ - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -571,9 +572,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "foldhash", ] @@ -631,7 +632,7 @@ dependencies = [ "instant", "number_prefix", "portable-atomic", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -1790,6 +1791,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "unsafe-libyaml" version = "0.2.11" diff --git a/Cargo.toml b/Cargo.toml index c741642..e1c2154 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ syntect = { version = "5.2", features = ["parsing", "regex-fancy", "dump-load"], tracing = "0.1" tracing-attributes = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } +unicode-width = "0.2" xxhash-rust = { version = "0.8", features = ["xxh3"] } zerocopy = { version = "0.8", features = ["derive"] } diff --git a/src/cmd/vfs.rs b/src/cmd/vfs.rs index d5c82d6..c3ac34b 100644 --- a/src/cmd/vfs.rs +++ b/src/cmd/vfs.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, bail, Context}; use argp::FromArgs; use size::Size; use typed_path::{Utf8NativePath, Utf8NativePathBuf, Utf8UnixPath}; +use unicode_width::UnicodeWidthStr; use crate::{ util::{file::buf_copy, path::native_path}, @@ -72,7 +73,7 @@ fn column_widths(entries: &[Columns]) -> [usize; N] { let mut widths = [0usize; N]; for text in entries { for (i, column) in text.iter().enumerate() { - widths[i] = widths[i].max(column.len()); + widths[i] = widths[i].max(column.width_cjk()); } } widths @@ -133,7 +134,11 @@ pub fn ls(args: LsArgs) -> anyhow::Result<()> { print!("{}", SEPARATOR); } written += 1; - print!("{:width$}", column, width = widths[i]); + print!("{}", column); + let remain = widths[i].saturating_sub(column.width_cjk()); + if remain > 0 { + print!("{:width$}", "", width = remain); + } } } println!();