codex icon indicating copy to clipboard operation
codex copied to clipboard

Respect terminal width

Open aehlke opened this issue 1 year ago • 9 comments

What version of Codex is running?

No response

Which model were you using?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

Resize terminal while running

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

aehlke avatar Aug 08 '25 12:08 aehlke

index 86d74141..99bfdff3 100644
--- a/codex-rs/tui/src/app.rs
+++ b/codex-rs/tui/src/app.rs
@@ -496,6 +496,8 @@ impl App<'_> {
         }
         terminal.draw(|frame| match &mut self.app_state {
             AppState::Chat { widget } => {
+                // Keep live streaming overlay wrapping in sync with current width
+                widget.update_live_width(frame.area());
                 if let Some((x, y)) = widget.cursor_pos(frame.area()) {
                     frame.set_cursor_position((x, y));
                 }
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index 8a47353c..55007cfe 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -110,6 +110,15 @@ fn create_initial_user_message(text: String, image_paths: Vec<PathBuf>) -> Optio
 }

 impl ChatWidget<'_> {
+    /// Ensure the live row builder width matches the current bottom pane width
+    /// so streamed output wraps at the correct terminal width.
+    pub(crate) fn update_live_width(&mut self, area: Rect) {
+        let [_, bottom_pane_area] = self.layout_areas(area);
+        let target = bottom_pane_area.width.max(1) as usize;
+        if self.live_builder.width() != target {
+            self.live_builder.set_width(target);
+        }
+    }
     fn interrupt_running_task(&mut self) {
         if self.bottom_pane.is_task_running() {
             self.active_history_cell = None;```

EspenG avatar Aug 08 '25 14:08 EspenG

Came here to say this also -- the hard wrap at 80 is not pleasant to work with, especially as it cuts words.

imajes avatar Aug 08 '25 16:08 imajes

@EspenG your patch won't cleanly apply as there have been other changes that mess with the index/diff line number markers.

However, i am testing it and it does make it go full with, which is great... though personally i'd prefer some padding (and also not wrapping/breaking words :/)

I wonder if the @openai folk are intending to use the other part of the width for other content?

imajes avatar Aug 08 '25 16:08 imajes

We're working on supporting full width with word wrap!

easong-openai avatar Aug 08 '25 17:08 easong-openai

@easong-openai I saw that pr landed and was reverted -- looking forward to seeing how that improves things. :)

ideally it'd be nice if it were possible to set a max width or similar in config - because the output is to be read, it's might be nice not to always have it super wide, without having to change the actual terminal itself.

imajes avatar Aug 08 '25 17:08 imajes

Agree! I use an iterm hotkey window on a 32 inch monitor and the full-terminal line wrapping is more than a little silly there. I think this is an improvement for enough users that we should add that in a later release.

easong-openai avatar Aug 08 '25 18:08 easong-openai

@easong-openai I was working on a similar PR, but figured I should see if the issue was even open. Very excited to hear!

Curious to see how my work differs when support lands.

Do you plan on doing line-breaks on syllables / phonemes, or just a hard column cutoff like currently?

callmemorgan avatar Aug 08 '25 22:08 callmemorgan

Just saw this issue. I was fixing the markdown render bug in the Rust CLI and realized that there is overlap with the lack of soft-wrap, so I fixed them both together: https://github.com/openai/codex/pull/2143 😃

rahulrajaram avatar Aug 10 '25 22:08 rahulrajaram

This feature hasn't received any upvotes or new posts in a long time, so I'm going to close it out.

We are actively exploring alternative terminal UI update mechanisms that would address this issue, but these alternative approaches have other tradeoffs. There's no solution that will address all terminal-related problems like this.

etraut-openai avatar Dec 31 '25 18:12 etraut-openai