count graphemes instead of chars in path length check

This commit is contained in:
sreedevk
2025-07-30 10:47:58 +00:00
parent 2191763b4d
commit da24efbb36
4 changed files with 12 additions and 3 deletions

View File

@@ -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<String> {
pub fn human_path(file: &FileInfo, aargs: &Params, max_path_length: usize) -> Result<String> {
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)

View File

@@ -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