diff --git a/crates/hyfetch/src/neofetch_util.rs b/crates/hyfetch/src/neofetch_util.rs index dadedff6..7612767e 100644 --- a/crates/hyfetch/src/neofetch_util.rs +++ b/crates/hyfetch/src/neofetch_util.rs @@ -16,6 +16,7 @@ use normpath::PathExt as _; use serde::{Deserialize, Serialize}; use tempfile::NamedTempFile; use tracing::debug; +use unicode_segmentation::UnicodeSegmentation; use crate::color_util::{ color, ForegroundBackground, NeofetchAsciiIndexedColor, PresetIndexedColor, ToAnsiString, @@ -455,7 +456,11 @@ where ac.replace_all(asc, &REPLACEMENTS) }; - let Some(width) = asc.split('\n').map(|line| line.len()).max() else { + let Some(width) = asc + .split('\n') + .map(|line| line.graphemes(true).count()) + .max() + else { unreachable!(); }; let width: u8 = width.try_into().expect("`width` should fit in `u8`"); diff --git a/crates/hyfetch/src/presets.rs b/crates/hyfetch/src/presets.rs index ac92547d..29e84187 100644 --- a/crates/hyfetch/src/presets.rs +++ b/crates/hyfetch/src/presets.rs @@ -482,6 +482,8 @@ impl ColorProfile { { let txt = txt.as_ref(); + let txt: Vec<&str> = txt.graphemes(true).collect(); + let ColorProfile { colors } = { let length = txt.len(); let length: u8 = length.try_into().expect("`length` should fit in `u8`"); @@ -490,7 +492,6 @@ impl ColorProfile { }; let mut buf = String::new(); - let txt: Vec<&str> = txt.graphemes(true).collect(); for (i, &gr) in txt.iter().enumerate() { if space_only && gr != " " { if i > 0 && txt[i - 1] == " " {