Fix TUI layout for halfwidth Japanese sound marks (#35962)

## What changed

- Use Ratatui-compatible terminal widths throughout TUI layout, preserving
  full-width counters for long lines.
- Wrap and truncate on grapheme boundaries so halfwidth kana sound marks and
  emoji sequences stay intact.
- Apply the corrected sizing to text input, selection popups, status and
  history cells, Markdown, hyperlinks, and scrollable cloud diffs.

## Testing

- Add focused unit and snapshot coverage for wrapping, truncation, cursor and
  mask alignment, popup columns, status output, session headers, Markdown
  tables, process output, and scrollable diffs.

GitOrigin-RevId: 294ec0bcff743c6bb16d55ec26308524ce741879
This commit is contained in:
Charlie Marsh authored and copyberry committed 2026-07-29 14:01:31 +00:00
1 parent cef3910ea4
commit 3725f02cf3
38 files changed
+1335 -245

No files matched your search

+4 -3
View File
@@ -1,6 +1,7 @@
//! Background terminal interaction and process-summary history cells.
use super::*;
use crate::width::display_width;
#[derive(Debug)]
pub(crate) struct UnifiedExecInteractionCell {
@@ -137,9 +138,9 @@ impl HistoryCell for UnifiedExecProcessesCell {
}
let prefix = " • ";
let prefix_width = UnicodeWidthStr::width(prefix);
let prefix_width = display_width(prefix);
let truncation_suffix = " [...]";
let truncation_suffix_width = UnicodeWidthStr::width(truncation_suffix);
let truncation_suffix_width = display_width(truncation_suffix);
let mut shown = 0usize;
for process in &self.processes {
if shown >= max_processes {
@@ -189,7 +190,7 @@ impl HistoryCell for UnifiedExecProcessesCell {
} else {
chunk_prefix_next
};
let chunk_prefix_width = UnicodeWidthStr::width(chunk_prefix);
let chunk_prefix_width = display_width(chunk_prefix);
if wrap_width <= chunk_prefix_width {
out.push(Line::from(chunk_prefix.dim()));
continue;
-1
View File
@@ -103,7 +103,6 @@ use std::time::Duration;
use std::time::Instant;
use tracing::error;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use url::Url;
const RAW_DIFF_SUMMARY_WIDTH: usize = 10_000;
+7 -16
View File
@@ -1,7 +1,9 @@
//! Session headers, onboarding guidance, and transcript cards.
use super::*;
use crate::line_truncation::line_width;
use crate::line_truncation::truncate_line_with_ellipsis_if_overflow;
use crate::width::display_width;
pub(crate) const SESSION_HEADER_MAX_INNER_WIDTH: usize = 56; // Just an eyeballed value
@@ -34,15 +36,7 @@ fn with_border_internal(
lines: Vec<Line<'static>>,
forced_inner_width: Option<usize>,
) -> Vec<Line<'static>> {
let max_line_width = lines
.iter()
.map(|line| {
line.iter()
.map(|span| UnicodeWidthStr::width(span.content.as_ref()))
.sum::<usize>()
})
.max()
.unwrap_or(0);
let max_line_width = lines.iter().map(line_width).max().unwrap_or(0);
let content_width = forced_inner_width
.unwrap_or(max_line_width)
.max(max_line_width);
@@ -52,10 +46,7 @@ fn with_border_internal(
out.push(vec![format!("╭{}╮", "─".repeat(border_inner_width)).dim()].into());
for line in lines.into_iter() {
let used_width: usize = line
.iter()
.map(|span| UnicodeWidthStr::width(span.content.as_ref()))
.sum();
let used_width = line_width(&line);
let span_count = line.spans.len();
let mut spans: Vec<Span<'static>> = Vec::with_capacity(span_count + 4);
spans.push(Span::from("│ ").dim());
@@ -90,7 +81,7 @@ impl TooltipHistoryCell {
impl HistoryCell for TooltipHistoryCell {
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
let indent = " ";
let indent_width = UnicodeWidthStr::width(indent);
let indent_width = display_width(indent);
let wrap_width = usize::from(width.max(1))
.saturating_sub(indent_width)
.max(1);
@@ -303,7 +294,7 @@ impl SessionHeaderHistoryCell {
if max_width == 0 {
return String::new();
}
if UnicodeWidthStr::width(formatted.as_str()) > max_width {
if display_width(formatted.as_str()) > max_width {
return crate::text_formatting::center_truncate_path(&formatted, max_width);
}
}
@@ -371,7 +362,7 @@ impl HistoryCell for SessionHeaderHistoryCell {
let dir_label = format!("{DIR_LABEL:<label_width$}");
let dir_prefix = format!("{dir_label} ");
let dir_prefix_width = UnicodeWidthStr::width(dir_prefix.as_str());
let dir_prefix_width = display_width(dir_prefix.as_str());
let dir_max_width = inner_width.saturating_sub(dir_prefix_width);
let dir = self.format_directory(Some(dir_max_width));
let dir_spans = vec![Span::from(dir_prefix).dim(), Span::from(dir)];
@@ -0,0 +1,10 @@
---
source: tui/src/history_cell/tests.rs
expression: rendered
---
/ps
Background terminals
• echo ガパガパ [...]
↳ output ガパ [...]
@@ -0,0 +1,26 @@
---
source: tui/src/history_cell/tests.rs
expression: "format!(\"{buf:?}\")"
---
Buffer {
area: Rect { x: 0, y: 0, width: 42, height: 6 },
content: [
"╭────────────────────────────────────────╮",
"│ >_ OpenAI Codex (vtest) │",
"│ │",
"│ model: gpt-5 /model to change │",
"│ directory: …パガパガパガパガパ-project │", // hidden by multi-width symbols: [(15, " "), (17, " "), (19, " "), (21, " "), (23, " "), (25, " "), (27, " "), (29, " "), (31, " ")]
"╰────────────────────────────────────────╯",
],
styles: [
x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 5, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD,
x: 17, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 13, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 18, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 21, y: 3, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
x: 27, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 40, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
]
}
@@ -0,0 +1,37 @@
---
source: tui/src/history_cell/tests.rs
expression: "format!(\"{buf:?}\")"
---
Buffer {
area: Rect { x: 0, y: 0, width: 80, height: 6 },
content: [
"╭───────────────────────────────────────────╮ ",
"│ >_ OpenAI Codex (vtest) │ ",
"│ │ ",
"│ model: gpt-5-ガ-パ /model to change │ ", // hidden by multi-width symbols: [(20, " "), (23, " ")]
"│ directory: project │ ",
"╰───────────────────────────────────────────╯ ",
],
styles: [
x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 5, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD,
x: 17, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 0, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 13, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 24, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 27, y: 3, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
x: 33, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 0, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 20, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 0, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
x: 45, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
]
}
+48
View File
@@ -783,6 +783,16 @@ fn ps_output_long_command_snapshot() {
insta::assert_snapshot!(rendered);
}
#[test]
fn ps_output_halfwidth_sound_marks_snapshot() {
let cell = new_unified_exec_processes_output(vec![UnifiedExecProcessDetails {
command_display: "echo ガパガパガパガパガパ".to_string(),
recent_chunks: vec!["output ガパガパガパガパガパ".to_string()],
}]);
let rendered = render_lines(&cell.display_lines(/*width*/ 24)).join("\n");
insta::assert_snapshot!(rendered);
}
#[test]
fn ps_output_many_sessions_snapshot() {
let cell = new_unified_exec_processes_output(
@@ -1653,6 +1663,44 @@ fn session_header_indicates_yolo_mode() {
insta::assert_snapshot!(rendered);
}
#[test]
fn session_header_aligns_halfwidth_sound_marks() {
let cell: Box<dyn HistoryCell> = Box::new(SessionHeaderHistoryCell::new(
"gpt-5-ガ-パ".to_string(),
/*reasoning_effort*/ None,
/*show_fast_status*/ false,
PathBuf::from("project"),
"test",
));
let width = 80;
let height = cell.desired_height(width);
let area = Rect::new(0, 0, width, height);
let mut buf = Buffer::empty(area);
cell.render(area, &mut buf);
insta::assert_snapshot!("session_header_halfwidth_sound_marks", format!("{buf:?}"));
}
#[test]
fn session_header_truncates_halfwidth_directory() {
let cell: Box<dyn HistoryCell> = Box::new(SessionHeaderHistoryCell::new(
"gpt-5".to_string(),
/*reasoning_effort*/ None,
/*show_fast_status*/ false,
PathBuf::from("ガパガパガパガパガパガパガパガパ-project"),
"test",
));
let width = 42;
let height = cell.desired_height(width);
let area = Rect::new(0, 0, width, height);
let mut buf = Buffer::empty(area);
cell.render(area, &mut buf);
insta::assert_snapshot!("session_header_halfwidth_directory", format!("{buf:?}"));
}
#[test]
fn yolo_mode_includes_managed_full_access_profiles() {
let permission_profile: PermissionProfile = PermissionProfile::Managed {