fix: use unicode-width to determine logo width

closes #68
This commit is contained in:
Adrian Groh 2025-01-21 21:58:25 +01:00
parent 912ba30d58
commit 6c591d2fd8
Signed by: Gobidev
GPG Key ID: 3AA3153E98B0D771
3 changed files with 12 additions and 3 deletions

9
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "aho-corasick"
@ -832,6 +832,7 @@ dependencies = [
"os-release",
"pfetch-extractor",
"pfetch-logo-parser",
"unicode-width",
"which",
]
@ -1161,6 +1162,12 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "walkdir"
version = "2.5.0"

View File

@ -24,6 +24,7 @@ which = "6.0.2"
libmacchina = "7.3.0"
crossterm = "0.28.1"
os-release = "0.1.0"
unicode-width = "0.2.0"
[profile.release]
strip = true

View File

@ -4,6 +4,7 @@ use libmacchina::{
};
use pfetch_logo_parser::{Color, Logo, LogoPart};
use std::{env, fmt::Display, str::FromStr};
use unicode_width::UnicodeWidthStr;
#[derive(Debug, PartialEq)]
enum PfetchInfo {
@ -73,7 +74,7 @@ fn pfetch(info: Vec<(Color, String, String)>, logo: Logo, logo_enabled: bool) {
let raw_logo_lines: Vec<_> = raw_logo.lines().collect();
let logo_width = raw_logo_lines
.iter()
.map(|line| line.chars().count())
.map(|line| line.width())
.max()
.unwrap_or(0);
let line_amount = usize::max(raw_logo_lines.len(), info.len());
@ -118,7 +119,7 @@ fn pfetch(info: Vec<(Color, String, String)>, logo: Logo, logo_enabled: bool) {
""
},
padding2 = " ".repeat(
logo_width - raw_logo_lines.get(l).map_or(0, |line| line.chars().count())
logo_width - raw_logo_lines.get(l).map_or(0, |line| line.width())
+ if logo_enabled { padding2 } else { 0 }
),
color = if color_enabled {info.get(l).map_or("".to_owned(), |line| line.0.to_string())} else {"".to_string()},