发布

  • fix: properly wrap lines in the Rust TUI (#937)

    frostbyte_neo 发布于 2025-05-14 23:51:41 +00:00

    As discussed on
    https://github.com/openai/codex/commit/bb60494cd2abcc06d045ab3d5ee02b7e3505bb7a#commitcomment-156776835,
    to properly support scrolling long content in Ratatui for a sequence of
    cells, we need to:

    • take the Vec<Line> for each cell
    • using the wrapping logic we want to use at render time, compute the
      effective line count using Paragraph::line_count() (see
      wrapped_line_count_for_cell() in this PR)
    • sum up the effective line count to compute the height of the area
      being scrolled
    • given a scroll_position: usize, index into the list of "effective
      lines" and accumulate the appropriate Vec<Line> for the cells that
      should be displayed
    • take that Vec<Line> to create a Paragraph and use the same
      line-wrapping policy that was used in wrapped_line_count_for_cell()
    • display the resulting Paragraph and use the accounting to display a
      scrollbar with the appropriate thumb size and offset without having to
      render the Vec<Line> for the full history

    With this change, lines wrap as I expect and everything appears to
    redraw correctly as I resize my terminal!

    下载附件