From da24efbb364f0b96e6571d83bcdf4bf928539220 Mon Sep 17 00:00:00 2001 From: sreedevk Date: Wed, 30 Jul 2025 10:47:58 +0000 Subject: [PATCH] count graphemes instead of chars in path length check --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/formatter.rs | 4 ++-- src/processor.rs | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d03f1d..99a277c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,6 +290,7 @@ dependencies = [ "rayon", "tempfile", "threadpool", + "unicode-segmentation", ] [[package]] @@ -898,6 +899,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "unicode-width" version = "0.1.14" diff --git a/Cargo.toml b/Cargo.toml index 9cd1ed1..30ebf2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ prettytable-rs = "0.10.0" rand = "0.9.1" rayon = "1.6.1" threadpool = "1.8.1" +unicode-segmentation = "1.12.0" [profile.release] strip = true diff --git a/src/formatter.rs b/src/formatter.rs index 9bfbb2e..29d61b1 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -12,14 +12,14 @@ const RESET: &str = "\x1b[0m"; pub struct Formatter; impl Formatter { - pub fn human_path(file: &FileInfo, aargs: &Params, min_path_length: usize) -> Result { + pub fn human_path(file: &FileInfo, aargs: &Params, max_path_length: usize) -> Result { let base_directory: PathBuf = aargs.get_directory()?; let relative_path = diff_paths(&file.path, base_directory).unwrap_or_default(); let formatted_path = format!( "{:<0width$}", relative_path.to_str().unwrap_or_default().to_string(), - width = min_path_length + width = max_path_length ); Ok(formatted_path) diff --git a/src/processor.rs b/src/processor.rs index 533cda8..1c20a3b 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -6,6 +6,7 @@ use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Mutex, TryLockError, TryLockResult}; use std::time::Duration; +use unicode_segmentation::UnicodeSegmentation; use crate::fileinfo::FileInfo; use crate::params::Params; @@ -64,7 +65,7 @@ impl Processor { Self::compare_and_update_max_path_len( max_file_size.clone(), - file.path.to_string_lossy().len() as u64, + file.path.to_string_lossy().graphemes(true).count() as u64, ); hw_store