diff --git a/Cargo.lock b/Cargo.lock index 4235a78..770a053 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index e711a15..426fcf5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/main.rs b/src/main.rs index 85740b8..6fba6b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()},