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:
@@ -124,6 +124,7 @@ impl ChatWidget {
|
||||
effects: local_settings.tui.effects,
|
||||
skills: None,
|
||||
}),
|
||||
bidi_layout: false,
|
||||
transcript: TranscriptState::new(active_cell),
|
||||
raw_output_mode: local_settings.tui.raw_output_mode,
|
||||
config,
|
||||
|
||||
@@ -266,6 +266,7 @@ impl ChatWidget {
|
||||
let active_cell_right_reserve = self.ambient_pet_wrap_reserved_cols();
|
||||
let active_cell_renderable = match &self.transcript.active_cell {
|
||||
Some(cell) => RenderableItem::Owned(Box::new(TranscriptAreaRenderable {
|
||||
bidi_layout: self.bidi_layout,
|
||||
child: cell.as_ref(),
|
||||
// The initial header becomes the first history cell, which has no leading separator.
|
||||
top: if cell.as_any().is::<history_cell::SessionHeaderHistoryCell>() {
|
||||
@@ -300,6 +301,7 @@ impl ChatWidget {
|
||||
flex.push(
|
||||
/*flex*/ 1,
|
||||
RenderableItem::Owned(Box::new(TranscriptAreaRenderable {
|
||||
bidi_layout: self.bidi_layout,
|
||||
child: cell.as_ref(),
|
||||
top: 1,
|
||||
right: active_cell_right_reserve,
|
||||
@@ -312,6 +314,7 @@ impl ChatWidget {
|
||||
flex.push(
|
||||
/*flex*/ 1,
|
||||
RenderableItem::Owned(Box::new(TranscriptAreaRenderable {
|
||||
bidi_layout: self.bidi_layout,
|
||||
child: cell,
|
||||
top: 1,
|
||||
right: active_cell_right_reserve,
|
||||
@@ -466,6 +469,7 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
struct TranscriptAreaRenderable<'a> {
|
||||
bidi_layout: bool,
|
||||
child: &'a dyn HistoryCell,
|
||||
top: u16,
|
||||
right: u16,
|
||||
@@ -482,7 +486,10 @@ struct PersistentActiveCellLayout<'a> {
|
||||
impl Renderable for TranscriptAreaRenderable<'_> {
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
let area = self.child_area(area);
|
||||
let lines = self.child.display_hyperlink_lines(area.width);
|
||||
let mut lines = self.child.display_hyperlink_lines(area.width);
|
||||
if self.bidi_layout {
|
||||
crate::terminal_hyperlinks::bidi::paint_rows(&mut lines, usize::from(area.width));
|
||||
}
|
||||
let paragraph = HyperlinkParagraph::new(&lines, Style::default());
|
||||
let y = if area.height == 0 {
|
||||
0
|
||||
|
||||
@@ -314,6 +314,7 @@ fn active_transcript_preserves_clipped_markdown_hyperlinks() {
|
||||
std::path::Path::new("/tmp"),
|
||||
);
|
||||
let renderable = TranscriptAreaRenderable {
|
||||
bidi_layout: false,
|
||||
child: &cell,
|
||||
top: 1,
|
||||
right: 2,
|
||||
|
||||
Reference in New Issue
Block a user