From b44ca3b39ea4e9d90cc85dfc4a749ceddc09d19e Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 26 Jun 2026 14:11:27 +0300 Subject: fix: measure ui labels by display width refs #810 --- src/ui/panes.rs | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) (limited to 'src/ui/panes.rs') diff --git a/src/ui/panes.rs b/src/ui/panes.rs index b11462d7..aa7bf0cd 100644 --- a/src/ui/panes.rs +++ b/src/ui/panes.rs @@ -5,9 +5,11 @@ use ratatui::{ widgets::{Block, Borders, Paragraph}, Frame, }; -use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use super::scrollbar::{render_pane_scrollbar, should_show_scrollbar}; +#[cfg(test)] +use super::text::display_width; +use super::text::truncate_end; use super::widgets::panel_contrast_fg; use crate::app::state::Palette; use crate::app::{AppState, Mode}; @@ -19,30 +21,6 @@ pub(crate) fn pane_is_scrolled_back(rt: &TerminalRuntime) -> bool { .is_some_and(|metrics| metrics.offset_from_bottom > 0) } -fn truncate_label(text: &str, max_width: usize) -> String { - if UnicodeWidthStr::width(text) <= max_width { - return text.to_string(); - } - if max_width == 0 { - return String::new(); - } - if max_width == 1 { - return "…".to_string(); - } - let mut prefix = String::new(); - let mut width = 0; - let prefix_width = max_width.saturating_sub(1); - for ch in text.chars() { - let ch_width = UnicodeWidthChar::width(ch).unwrap_or(0); - if width + ch_width > prefix_width { - break; - } - prefix.push(ch); - width += ch_width; - } - format!("{prefix}…") -} - fn pane_border_title(label: &str, pane_width: u16, focused: bool) -> Option { let label = label.trim(); if label.is_empty() || pane_width <= 4 { @@ -50,10 +28,10 @@ fn pane_border_title(label: &str, pane_width: u16, focused: bool) -> Option