ratatui/tests
Neal Fachan d72968d86b
feat(scrolling-regions)!: use terminal scrolling regions to stop Terminal::insert_before from flickering (#1341)
The current implementation of Terminal::insert_before causes the
viewport to flicker. This is described in #584 .

This PR removes that flickering by using terminal scrolling regions
(sometimes called "scroll regions"). A terminal can have its scrolling
region set to something other than the whole screen. When a scroll ANSI
sequence is sent to the terminal and it has a non-default scrolling
region, the terminal will scroll just inside of that region.

We use scrolling regions to implement insert_before. We create a region
on the screen above the viewport, scroll that up to make room for the
newly inserted lines, and then draw the new lines. We may need to repeat
this process depending on how much space there is and how many lines we
need to draw.

When the viewport takes up the entire screen, we take a modified
approach. We create a scrolling region of just the top line (could be
more) of the viewport, then use that to draw the lines we want to
output. When we're done, we scroll it up by one line, into the
scrollback history, and then redraw the top line from the viewport.

A final edge case is when the viewport hasn't yet reached the bottom of
the screen. This case, we set up a different scrolling region, where the
top is the top of the viewport, and the bottom is the viewport's bottom
plus the number of lines we want to scroll by. We then scroll this
region down to open up space above the viewport for drawing the inserted
lines.

Regardless of what we do, we need to reset the scrolling region. This PR
takes the approach of always resetting the scrolling region after every
operation. So the Backend gets new scroll_region_up and
scroll_region_down methods instead of set_scrolling_region, scroll_up,
scroll_down, and reset_scrolling_region methods. We chose that approach
for two reasons. First, we don't want Ratatui to have to remember that
state and then reset the scrolling region when tearing down. Second, the
pre-Windows-10 console code doesn't support scrolling regio

This PR:
- Adds a new scrolling-regions feature.
- Adds two new Backend methods: scroll_region_up and scroll_region_down.
- Implements those Backend methods on all backends in the codebase.
- The crossterm and termion implementations use raw ANSI escape
sequences. I'm trying to merge changes into those two projects
separately to support these functions.
- Adds code to Terminal::insert_before to choose between
insert_before_scrolling_regions and insert_before_no_scrolling_regions.
The latter is the old implementation.
- Adds lots of tests to the TestBackend to for the
scrolling-region-related Backend methods.
- Adds versions of terminal tests that show that insert_before doesn't
clobber the viewport. This is a change in behavior from before.
2024-10-14 15:46:13 -07:00
..
backend_termion.rs build: simplify Windows build (#1317) 2024-08-13 10:09:46 -07:00
state_serde.rs feat(table)!: add support for selecting column and cell (#1331) 2024-10-13 14:06:29 +03:00
stylize.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
terminal.rs feat(scrolling-regions)!: use terminal scrolling regions to stop Terminal::insert_before from flickering (#1341) 2024-10-14 15:46:13 -07:00
widgets_barchart.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
widgets_block.rs chore(block): deprecate block::Title (#1372) 2024-09-20 10:21:26 +03:00
widgets_calendar.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
widgets_canvas.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
widgets_chart.rs feat(chart)!: accept IntoIterator for axis labels (#1283) 2024-08-06 11:39:44 +02:00
widgets_gauge.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
widgets_list.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
widgets_paragraph.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
widgets_table.rs feat(table)!: add support for selecting column and cell (#1331) 2024-10-13 14:06:29 +03:00
widgets_tabs.rs refactor(buffer): deprecate assert_buffer_eq! in favor of assert_eq! (#1007) 2024-05-13 18:13:46 -07:00