Skip to content

Commit 6c591d2

Browse files
committed
fix: use unicode-width to determine logo width
closes #68
1 parent 912ba30 commit 6c591d2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ which = "6.0.2"
2424
libmacchina = "7.3.0"
2525
crossterm = "0.28.1"
2626
os-release = "0.1.0"
27+
unicode-width = "0.2.0"
2728

2829
[profile.release]
2930
strip = true

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use libmacchina::{
44
};
55
use pfetch_logo_parser::{Color, Logo, LogoPart};
66
use std::{env, fmt::Display, str::FromStr};
7+
use unicode_width::UnicodeWidthStr;
78

89
#[derive(Debug, PartialEq)]
910
enum PfetchInfo {
@@ -73,7 +74,7 @@ fn pfetch(info: Vec<(Color, String, String)>, logo: Logo, logo_enabled: bool) {
7374
let raw_logo_lines: Vec<_> = raw_logo.lines().collect();
7475
let logo_width = raw_logo_lines
7576
.iter()
76-
.map(|line| line.chars().count())
77+
.map(|line| line.width())
7778
.max()
7879
.unwrap_or(0);
7980
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) {
118119
""
119120
},
120121
padding2 = " ".repeat(
121-
logo_width - raw_logo_lines.get(l).map_or(0, |line| line.chars().count())
122+
logo_width - raw_logo_lines.get(l).map_or(0, |line| line.width())
122123
+ if logo_enabled { padding2 } else { 0 }
123124
),
124125
color = if color_enabled {info.get(l).map_or("".to_owned(), |line| line.0.to_string())} else {"".to_string()},

0 commit comments

Comments
 (0)