mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Keep bidirectional TUI headers stable during shimmer (#61731)
## Why Per-grapheme color updates can break native terminal bidirectional rendering in thinking and reasoning headers. ## What changed Render text containing strong right-to-left characters or Arabic numbers as a single, static dimmed span in both shimmer implementations. Preserve logical text order and use one-second clock updates for these status headers when progress animation is disabled. ## Testing Add snapshot coverage for Hebrew, Arabic, mixed-direction text, and Arabic numbers, checking that headers remain unchanged during the shimmer sweep. Add scheduling tests for static headers and active progress animation. GitOrigin-RevId: 911abc50f00db597ae4dcfca9941e9f63547c2f9
This commit is contained in:
@@ -130,6 +130,7 @@ tracing-appender = { workspace = true }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
||||
syntect = { version = "5", default-features = false, features = ["parsing", "plist-load", "regex-onig"] }
|
||||
two-face = { version = "0.5", default-features = false, features = ["syntect-onig"] }
|
||||
unicode-bidi = { workspace = true }
|
||||
unicode-linebreak = { workspace = true }
|
||||
unicode-segmentation = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::text_formatting::contains_rtl_or_arabic_number;
|
||||
use crate::tui::FrameRequester;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Span;
|
||||
@@ -85,6 +86,7 @@ pub(crate) fn activity_indicator(
|
||||
|
||||
pub(crate) fn shimmer_text(text: &str, motion_mode: MotionMode) -> Vec<Span<'static>> {
|
||||
match motion_mode {
|
||||
MotionMode::Animated if contains_rtl_or_arabic_number(text) => vec![text.to_owned().dim()],
|
||||
MotionMode::Animated => shimmer_spans(text),
|
||||
MotionMode::Reduced => {
|
||||
if text.is_empty() {
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/summary_shimmer_tests.rs
|
||||
expression: headers
|
||||
---
|
||||
[
|
||||
[
|
||||
Span::from("שלום עולם").dim(),
|
||||
],
|
||||
[
|
||||
Span::from("Checking ש\u{5b8}\u{5c1}לו\u{5b9}ם (test.rs) 123").dim(),
|
||||
],
|
||||
[
|
||||
Span::from("Checking lines ١٢-٣٤").dim(),
|
||||
],
|
||||
[
|
||||
Span::from("مرحبا").dim(),
|
||||
],
|
||||
]
|
||||
@@ -31,6 +31,7 @@ use crate::motion::ReducedMotionIndicator;
|
||||
use crate::motion::activity_indicator;
|
||||
use crate::render::renderable::Renderable;
|
||||
use crate::text_formatting::capitalize_first;
|
||||
use crate::text_formatting::contains_rtl_or_arabic_number;
|
||||
use crate::tui::FrameRequester;
|
||||
use crate::width::display_width;
|
||||
use crate::wrapping::RtOptions;
|
||||
@@ -303,7 +304,9 @@ impl Renderable for StatusIndicator<'_> {
|
||||
}
|
||||
if self.row.animations_enabled || self.timer.display_started_at.is_some() {
|
||||
let interval_ms = if self.row.animations_enabled
|
||||
&& (self.row.effects.progress || self.row.effects.shimmer)
|
||||
&& (self.row.effects.progress
|
||||
|| (self.row.effects.shimmer
|
||||
&& !contains_rtl_or_arabic_number(&self.row.header)))
|
||||
{
|
||||
32
|
||||
} else {
|
||||
@@ -345,6 +348,39 @@ mod tests {
|
||||
assert!(row.header_started_at > previous);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn static_bidi_headers_only_schedule_clock_ticks_without_progress() {
|
||||
for (header, progress, expected_ms) in [
|
||||
("שלום עולם", false, 1_000),
|
||||
("Checking lines ١٢-٣٤", false, 1_000),
|
||||
("Working", false, 32),
|
||||
("שלום עולם", true, 32),
|
||||
] {
|
||||
let (tx, _rx) = unbounded_channel();
|
||||
let (requester, mut requests) = FrameRequester::test_channel();
|
||||
let mut row = StatusIndicatorWidget::new(
|
||||
AppEventSender::new(tx),
|
||||
requester,
|
||||
/*animations_enabled*/ true,
|
||||
codex_config::types::TuiEffects {
|
||||
progress,
|
||||
shimmer: true,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
row.update_header(header.to_owned());
|
||||
let timer = StatusTimer::default();
|
||||
let area = Rect::new(0, 0, 80, 1);
|
||||
let before = Instant::now();
|
||||
row.with_timer(&timer)
|
||||
.render(area, &mut Buffer::empty(area));
|
||||
let after = Instant::now();
|
||||
let requested = requests.try_recv().expect("scheduled frame");
|
||||
let interval = Duration::from_millis(expected_ms);
|
||||
assert!((before + interval..=after + interval).contains(&requested));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_elapsed_compact_formats_seconds_minutes_hours() {
|
||||
assert_eq!(fmt_elapsed_compact(/*elapsed_secs*/ 0), "0s");
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::terminal_palette::default_bg;
|
||||
use crate::terminal_palette::default_fg;
|
||||
use crate::terminal_palette::effective_stdout_color_level;
|
||||
use crate::terminal_palette::rgb_color;
|
||||
use crate::text_formatting::contains_rtl_or_arabic_number;
|
||||
|
||||
// Match the desktop app's thinking and reasoning header timings.
|
||||
const START_DELAY: Duration = Duration::from_millis(/*millis*/ 600);
|
||||
@@ -34,6 +35,11 @@ pub(crate) fn summary_shimmer(
|
||||
if motion == MotionMode::Reduced {
|
||||
return vec![text.to_owned().into()];
|
||||
}
|
||||
// Per-grapheme color updates redraw individual terminal cells and break native bidi
|
||||
// rendering. Keep bidi-sensitive headers as one stable span in logical order.
|
||||
if contains_rtl_or_arabic_number(text) {
|
||||
return vec![Span::styled(text.to_owned(), Style::default().dim())];
|
||||
}
|
||||
let (StdoutColorLevel::TrueColor, Some(fg), Some(bg)) =
|
||||
(effective_stdout_color_level(), default_fg(), default_bg())
|
||||
else {
|
||||
|
||||
@@ -4,6 +4,39 @@ use pretty_assertions::assert_eq;
|
||||
use crate::terminal_palette::with_test_default_colors;
|
||||
use crate::terminal_probe::DefaultColors;
|
||||
|
||||
#[test]
|
||||
fn rtl_headers_remain_stable_during_the_sweep() {
|
||||
with_test_default_colors(
|
||||
DefaultColors {
|
||||
fg: (240, 240, 240),
|
||||
bg: (16, 16, 16),
|
||||
},
|
||||
|| {
|
||||
let mut headers = Vec::new();
|
||||
for text in [
|
||||
"שלום עולם",
|
||||
"Checking שָׁלוֹם (test.rs) 123",
|
||||
"Checking lines ١٢-٣٤",
|
||||
"مرحبا",
|
||||
] {
|
||||
let initial = summary_shimmer(text, Duration::ZERO, MotionMode::Animated);
|
||||
let sweep = summary_shimmer(
|
||||
text,
|
||||
Duration::from_millis(/*millis*/ 1100),
|
||||
MotionMode::Animated,
|
||||
);
|
||||
assert_eq!(initial, sweep);
|
||||
assert_eq!(
|
||||
initial,
|
||||
crate::motion::shimmer_text(text, MotionMode::Animated)
|
||||
);
|
||||
headers.push(initial);
|
||||
}
|
||||
insta::assert_debug_snapshot!(headers);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_and_long_labels_sweep_smoothly_in_both_themes() {
|
||||
let mut frames = Vec::new();
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
use unicode_bidi::BidiClass;
|
||||
use unicode_bidi::bidi_class;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::width::display_width;
|
||||
|
||||
/// Returns whether the text contains a strong RTL character or an Arabic number.
|
||||
pub(crate) fn contains_rtl_or_arabic_number(text: &str) -> bool {
|
||||
text.chars()
|
||||
.any(|c| matches!(bidi_class(c), BidiClass::R | BidiClass::AL | BidiClass::AN))
|
||||
}
|
||||
|
||||
pub(crate) fn capitalize_first(input: &str) -> String {
|
||||
let mut chars = input.chars();
|
||||
match chars.next() {
|
||||
|
||||
Reference in New Issue
Block a user