diff options
author | Paulo Coelho <9609090+prscoelho@users.noreply.github.com> | 2021-09-12 19:29:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-12 20:29:07 +0200 |
commit | aae9c9c807d5990fb3cdc6fcb3fd0bb8c3c3c7f2 (patch) | |
tree | 2a565e6aecc5f3346633c6ae7b3ed3cafc3483fd /zellij-utils | |
parent | 8888476885d80a5727ac9c23f2e4c288b75aadb8 (diff) |
Calculate width with unicode-width in tab-bar and utils (#709)
* fix(tab-bar): calculate string width using unicode-width
* fix(utils): calculate ansi_len using unicode-width
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/Cargo.toml | 1 | ||||
-rw-r--r-- | zellij-utils/src/shared.rs | 6 |
2 files changed, 3 insertions, 4 deletions
diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 6e4b72cc1..838b0c57b 100644 --- a/zellij-utils/Cargo.toml +++ b/zellij-utils/Cargo.toml @@ -30,6 +30,7 @@ vte = "0.10.1" zellij-tile = { path = "../zellij-tile/", version = "0.17.0" } log = "0.4.14" log4rs = "1.0.0" +unicode-width = "0.1.8" [dependencies.async-std] version = "1.3.0" diff --git a/zellij-utils/src/shared.rs b/zellij-utils/src/shared.rs index 4b3ba9745..06d1378db 100644 --- a/zellij-utils/src/shared.rs +++ b/zellij-utils/src/shared.rs @@ -7,6 +7,7 @@ use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::{fs, io}; use strip_ansi_escapes::strip; +use unicode_width::UnicodeWidthStr; use zellij_tile::data::{Palette, PaletteColor, PaletteSource, ThemeHue}; const UNIX_PERMISSIONS: u32 = 0o700; @@ -18,10 +19,7 @@ pub fn set_permissions(path: &Path) -> io::Result<()> { } pub fn ansi_len(s: &str) -> usize { - from_utf8(&strip(s.as_bytes()).unwrap()) - .unwrap() - .chars() - .count() + from_utf8(&strip(s.as_bytes()).unwrap()).unwrap().width() } pub fn adjust_to_size(s: &str, rows: usize, columns: usize) -> String { |