From b736853dfe76f14e6b72eda2e4dd3dc09410fc5b Mon Sep 17 00:00:00 2001 From: Andrey Ryabov Date: Thu, 12 Jan 2023 21:43:31 +0200 Subject: [PATCH] Take 32 grapheme clusters instead of characters --- Cargo.toml | 1 + src/output.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba61aac..855b7f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ sqlite = "0.30.3" thiserror = "1.0.38" tokio = { version = "1.23.0", features = ["full"] } tui = "0.19.0" +unicode-segmentation = "1.10.0" diff --git a/src/output.rs b/src/output.rs index ff216f7..fcc2518 100644 --- a/src/output.rs +++ b/src/output.rs @@ -12,14 +12,16 @@ use crate::app::file_manager; use crate::database::File; use crate::params::Params; use prettytable::{format, row, Cell, Row, Table}; +use unicode_segmentation::UnicodeSegmentation; fn format_path(path: &str, opts: &Params) -> Result { let display_path = path.replace(&opts.get_directory()?, ""); - let text_vec = display_path.chars().collect::>(); - let display_range = if text_vec.len() < 32 { - text_vec - .iter() + let display_range = if display_path.chars().count() > 32 { + display_path + .graphemes(true) + .collect::>() + .into_iter() .rev() .take(32) .rev()