Skip to content

feat: read the normal screen under the alternate one - #52

Open
mxaddict wants to merge 2 commits into
doy:mainfrom
kryptic-sh:saved-screen
Open

mxaddict wants to merge 2 commits into
doy:mainfrom
kryptic-sh:saved-screen

Conversation

@mxaddict

Copy link
Copy Markdown

Builds on #50 (it returns rows as Screen::line_cells does); only the last
commit is new here.

While the alternate screen is shown, nothing reads the normal screen it hides:
Screen::cell, Screen::rows and Screen::line_cells all read the shown grid,
and the normal one is private. A terminal multiplexer needs it for tmux's
capture-pane -a, which captures exactly that (tmux's saved_grid: the normal
screen's rows as they were when the alternate screen came on).

  • Screen::normal_screen_row_cells(row): the cells of that row of the normal
    screen while the alternate screen is shown; None otherwise or past the last
    row.
  • Screen::normal_screen_row_wrapped(row): whether that row wraps.

Entering the alternate screen already resets the normal grid's scrollback
offset, so its visible rows are the screen as it was.

Test

tests/mode.rs: normal_screen_rows_read_under_the_alternate_screen (None
before and after the alternate screen; the rows, a wrapped one among them,
while it shows). It fails when the shown grid is read instead, and when the
alternate-screen check is dropped.

cargo nextest run --all-targets, doc tests,
cargo clippy --all-targets -- -Dwarnings, cargo fmt --check, cargo doc
and cargo +1.85.0 check --lib --all-features pass locally.

Reading the whole scrollback (to copy it out, as a multiplexer's copy
mode does) meant stepping set_scrollback through it a screenful at a
time and calling Screen::cell for each cell, which widens each row it
shows and copies cell by cell. line_cells returns a line of scrollback
or screen as a slice, by its index from the oldest scrollback row, and
line_wrapped its wrap flag, without moving the view.
While the alternate screen is shown, the normal screen it hides could
not be read: Screen::cell and Screen::line_cells read the shown grid.
Screen::normal_screen_row_cells and normal_screen_row_wrapped give its
rows, as they were when the alternate screen came on, which is what
tmux's capture-pane -a reads.
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.

1 participant