mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-21 20:23:11 +00:00
d72968d86b
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. |
||
---|---|---|
.. | ||
backend_termion.rs | ||
state_serde.rs | ||
stylize.rs | ||
terminal.rs | ||
widgets_barchart.rs | ||
widgets_block.rs | ||
widgets_calendar.rs | ||
widgets_canvas.rs | ||
widgets_chart.rs | ||
widgets_gauge.rs | ||
widgets_list.rs | ||
widgets_paragraph.rs | ||
widgets_table.rs | ||
widgets_tabs.rs |