Lightweight coding agent that runs in your terminal
Rust
tui: wrapping bugfix (#4674)
Jeremy Rose4b0f5eb6a825
diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rsindex e3a89da340..61640c3334 100644--- a/codex-rs/tui/src/history_cell.rs+++ b/codex-rs/tui/src/history_cell.rs@@ -104,7 +104,8 @@ impl HistoryCell for UserHistoryCell {.lines().map(|l| Line::from(l).style(style)).collect::<Vec<_>>(),- RtOptions::new(wrap_width as usize),+ // Wrap algorithm matches textarea.rs.+ RtOptions::new(wrap_width as usize).wrap_algorithm(textwrap::WrapAlgorithm::FirstFit),);lines.push(Line::from("").style(style));diff --git a/codex-rs/tui/src/wrapping.rs b/codex-rs/tui/src/wrapping.rsindex da79f036b4..70ca2e46ca 100644--- a/codex-rs/tui/src/wrapping.rs+++ b/codex-rs/tui/src/wrapping.rs@@ -2,6 +2,7 @@ use ratatui::text::Line;use ratatui::text::Span;use std::ops::Range;use textwrap::Options;+use textwrap::wrap_algorithms::Penalties;use crate::render::line_utils::push_owned_lines;@@ -90,7 +91,11 @@ impl<'a> RtOptions<'a> {subsequent_indent: Line::default(),break_words: true,word_separator: textwrap::WordSeparator::new(),- wrap_algorithm: textwrap::WrapAlgorithm::new(),+ wrap_algorithm: textwrap::WrapAlgorithm::OptimalFit(Penalties {+ // ~infinite overflow penalty, we never want to overflow a line.+ overflow_penalty: usize::MAX / 4,+ ..Default::default()+ }),word_splitter: textwrap::WordSplitter::HyphenSplitter,}}