feat(tui): render responsive Markdown tables in TUI#22052
Conversation
etraut-openai
left a comment
There was a problem hiding this comment.
Nice! This is going to make a lot of TUI users happy.
In addition to reviewing the code, I tested using multiple terminals (terminal.app, iTerm2, Kitty, Ghostty, Codex app terminal). I also tested many different sizes and shapes of markdown tables and different widths and heights and color themes.
Overall, it worked well. I found a few issues that I consider edge cases. I think we could ship the current implementation without addressing these. Items 4 and 5 look like legit bugs that users could hit.
- When I resize the window to narrower during streaming a markdown table, I sometimes see the table redraw over the top of existing content without replacing that content in areas where there is "white space" within the table. The problem corrects itself once the table is fully streamed.
- I manually disabled the
terminal_resize_reflowfeature flag, and the new functionality (not surprisingly) doesn't work well when resize reflow is disabled. Since this is on by default, I don't think this is a big deal. We will probably deprecate theterminal_resize_reflowflag soon anyway. - When the terminal is narrower, sometimes that markdown table doesn't render as a table and instead renders as the raw markdown characters. For example, I asked the agent to emit a table with 30 columns. At a typical terminal width, this doesn't render as a table. I'm not sure whether this is an intentional design choice or a bug. It seems like a reasonable fallback when the table is too wide.
- Codex found a bug related to plan mode results that are presented as a table. They render correctly during streaming but then are rendered as raw markdown text after streaming completes. To repro, use this prompt in plan mode:
Please only propose a plan and then stop. Do not inspect files or run commands.
In the proposed plan, include this exact fenced markdown table as the main plan content:
```md
| Step | Owner |
|---|---|
| Write tests | Agent |
| Verify output | User |
```
- Codex also found a bug in the spillover detection logic. To repro, use the following prompt:
Reply with exactly this markdown table and no other text:
| Name | Notes | Status |
|---|---|---|
| First | normal | ok |
| HTML block: | | |
- A few of the code files (markdown_renderer.rs and streaming/controller.rs) are getting really large. We may want to break these into smaller submodules. This can wait for future PRs.
Thank you for the review!
I agree, let's ship this as soon as I rebase from main.
Noted.
Yes, I agree with the judgement here. We could keep old behavior in this case, but since we are deprecating it anyways, may not be worth the trouble.
I think we should have a fallback that renders the table with each column as a row and separate each row. I have that ready and will send a subsequent PR.
This is a bad omission, let me evaluate how hard it is to include this one on this PR and I'll make a decision.
This one might be possible to fix as well, let me take a look.
Yes, let's add this to the follow-up candidates. |
d3b89df to
0f6607e
Compare
Why
The TUI currently treats Markdown tables as ordinary wrapped text, which makes table-heavy responses hard to read and brittle across narrow panes and terminal resizes.
This change teaches the TUI to render Markdown tables responsively while preserving the raw Markdown source needed to re-render streamed and finalized transcript content after width changes. The goal is to keep tables legible during streaming, after resize, and once a turn has finished, without corrupting scrollback ordering.
What Changed
<br>content inside table cells instead of leaking text outside the tableHow to Test
This is a session to test codex, no need to do any thinking, just end different markdown tables, with columns exploring different markdown contents, like links, bold italic, code, etc. Make them different sizes, some 30+ rows, some not and intertwine them with some paragraphs with complex formatting as well.Targeted tests:
cargo test -p codex-tui table_readability_fallback --no-fail-fastcargo test -p codex-tui markdown_render --no-fail-fastcargo test -p codex-tui streaming::controller --no-fail-fastcargo test -p codex-tui table_resize_lifecycle --no-fail-fastDocs
No developer docs update appears necessary.