From 2e5b344c04fca694d154ea88d5cd0c29231cf10c Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Wed, 24 Mar 2021 11:16:01 +0100 Subject: [PATCH] branchlist was ignoring unicode boundaries on truncating strings (#603) * branchlist was ignoring unicode boundaries on truncating strings (fixes #602) --- Cargo.lock | 9 +++++++++ Cargo.toml | 1 + src/components/branchlist.rs | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a59ea1c2..6dff1eeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -366,6 +366,7 @@ dependencies = [ "simplelog", "textwrap 0.13.4", "tui", + "unicode-truncate", "unicode-width", "which", ] @@ -1173,6 +1174,14 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +[[package]] +name = "unicode-truncate" +version = "0.2.0" +source = "git+https://github.com/Aetf/unicode-truncate.git#b1821b0af6801b81e1f1f900526748754f8cd44f" +dependencies = [ + "unicode-width", +] + [[package]] name = "unicode-width" version = "0.1.8" diff --git a/Cargo.toml b/Cargo.toml index 667b256a..25ddc6d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ serde = "1.0" anyhow = "1.0" unicode-width = "0.1" textwrap = "0.13" +unicode-truncate = {version="0.2", git="https://github.com/Aetf/unicode-truncate.git"} [target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies] which = "4.0" diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 484ba864..ebe7acf3 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -25,6 +25,7 @@ use tui::{ widgets::{Block, BorderType, Borders, Clear, Paragraph}, Frame, }; +use unicode_truncate::UnicodeTruncateStr; use crate::ui::Size; use anyhow::Result; @@ -334,7 +335,7 @@ impl BranchListComponent { let mut commit_message = displaybranch.top_commit_message.clone(); if commit_message.len() > commit_message_length { - commit_message.truncate( + commit_message.unicode_truncate( commit_message_length .saturating_sub(THREE_DOTS_LENGTH), ); @@ -343,7 +344,7 @@ impl BranchListComponent { let mut branch_name = displaybranch.name.clone(); if branch_name.len() > branch_name_length { - branch_name.truncate( + branch_name.unicode_truncate( branch_name_length .saturating_sub(THREE_DOTS_LENGTH), );