Skip to content

Commit

Permalink
fix: use unicode-width to determine logo width
Browse files Browse the repository at this point in the history
closes #68
  • Loading branch information
Gobidev committed Jan 21, 2025
1 parent 912ba30 commit 6c591d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()},
Expand Down

0 comments on commit 6c591d2

Please sign in to comment.