Skip to content

refactor: Extract shared layout computation from painter#1021

Merged
fdncred merged 2 commits intonushell:mainfrom
stuartcarnie:refactor_layout
Feb 5, 2026
Merged

refactor: Extract shared layout computation from painter#1021
fdncred merged 2 commits intonushell:mainfrom
stuartcarnie:refactor_layout

Conversation

@stuartcarnie
Copy link
Contributor

  • Introduce PromptLayout struct computed once per paint cycle in compute_layout, eliminating duplicated layout math across print_large_buffer, print_right_prompt, print_menu, and render_snapshot
  • Fix bug where render_snapshot rendered the right prompt for large buffers even when the prompt had scrolled off-screen (extra_rows > 0), diverging from print_large_buffer which correctly suppressed it
  • Add 7 unit tests covering compute_layout (small/large buffer, right prompt visibility, scrolling math, multi-line prompt)

Motivation

render_snapshot duplicated layout calculations from print_large_buffer, print_right_prompt, and print_menu. Any change to one had to be mirrored in the other, and they had already drifted (the right-prompt suppression bug).

Changes

src/painting/painter.rs

  • Add PromptLayout struct holding all layout values: extra rows, large buffer offset, right prompt bounds, menu start row, first buffer column
  • Add Painter::compute_layout() that consolidates the 5 duplicated computations into a single call
  • Add Painter::last_layout field storing the layout from the most recent paint cycle
  • Update repaint_buffer to call compute_layout and thread the result through print_large_buffer, print_small_buffer, print_right_prompt, and print_menu
  • Simplify render_snapshot to copy values from the layout instead of recomputing them

Replace the redundant `right_prompt_rendered` bool and three separate
Option fields with a single `Option<RightPromptBounds>` struct in both
PromptLayout and RenderSnapshot, ensuring the fields are always set
or unset together. Add unit tests for compute_layout.
@fdncred
Copy link
Contributor

fdncred commented Feb 5, 2026

Nice cleanup. Thanks!

@fdncred fdncred merged commit f7ac814 into nushell:main Feb 5, 2026
6 checks passed
@stuartcarnie stuartcarnie deleted the refactor_layout branch February 14, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants