mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Render bidirectional transcript text on terminals without native ordering (#63844)
## Why Terminals that leave bidirectional ordering to the application can display Arabic and Hebrew transcript text in the wrong order, especially when it includes URLs, numbers, or inline code. ## What changed Use the terminal's bidirectional mode report when available on a direct connection, with a fallback for Windows Terminal, Ghostty, and Alacritty. Resolve direction before wrapping and reorder graphemes for display in the live transcript and scrollback. Preserve styling, hyperlink destinations, and logical text for copying. Keep URLs and inline literals left to right, and skip reordering for code blocks, tables, and lines with shell syntax that could be misrepresented. Measure hyperlink columns by painted graphemes so Arabic ligatures do not shift clickable ranges in the transcript or composer. ## Testing Cover agreement between streaming and finalized scrollback, preservation of shell command boundaries, startup probe reply handling, and wrapped composer links following Arabic text. GitOrigin-RevId: 9ffa0f491a93c78fef423acfc6a951cb037abd4d
This commit is contained in:
@@ -9,7 +9,7 @@ use ratatui::text::Span;
|
||||
use crate::terminal_hyperlinks::HyperlinkLine;
|
||||
use crate::terminal_hyperlinks::LineWrapPolicy;
|
||||
use crate::terminal_hyperlinks::LogicalLineSource;
|
||||
use crate::width::display_width;
|
||||
use crate::terminal_hyperlinks::source_text_width;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct LogicalLine {
|
||||
@@ -66,7 +66,11 @@ impl LogicalLine {
|
||||
);
|
||||
let prefix = slice_line(&line.line, 0..source.prefix_bytes);
|
||||
let prefix_width = prefix.width();
|
||||
let content_width = display_width(&source.text[source.range.clone()]);
|
||||
let content_width = if line.hyperlinks.is_empty() {
|
||||
0
|
||||
} else {
|
||||
source_text_width(&source.text[source.range.clone()])
|
||||
};
|
||||
self.line.line.spans.extend(body.spans);
|
||||
self.line
|
||||
.hyperlinks
|
||||
|
||||
@@ -481,3 +481,31 @@ fn document_link_navigation_preserves_occurrences_across_wraps() {
|
||||
assert_eq!(links, ["first link wraps", "second link"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_transcript_preserves_command_boundaries() {
|
||||
use crate::terminal_hyperlinks::bidi;
|
||||
let paint = |command: &'static str| {
|
||||
let mut lines = prefix_hyperlink_lines(vec![command.into()], "".into(), "".into());
|
||||
bidi::prepare_message(&mut lines);
|
||||
bidi::paint_rows(&mut lines, /*width*/ 80);
|
||||
lines[0].line.to_string()
|
||||
};
|
||||
assert_eq!(
|
||||
paint(": שלום https://example.org/?x=1&make"),
|
||||
": םולש https://example.org/?x=1&make"
|
||||
);
|
||||
for command in [
|
||||
"echo SAFE \u{2067}שלום printf PWNED\u{2069}\u{200f}",
|
||||
": \u{070f} שלום printf PWNED",
|
||||
": שלום; echo SAFE; printf PWNED #",
|
||||
"שלום; echo SAFE; printf PWNED #",
|
||||
"שלום & calc.exe & עולם & ::",
|
||||
"שלום $(touch /tmp/PWNED)",
|
||||
"שלום https://example.org/?a=1&b=2 #",
|
||||
"שלום & https://example.org/#help",
|
||||
"שלום https://example.org/$name#help",
|
||||
] {
|
||||
assert_eq!(paint(command), command);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user