ttx 0.1.0
Loading...
Searching...
No Matches
ttx::terminal::ScrollBack Class Reference

Represents the terminal scroll back. More...

#include <ttx/terminal/scroll_back.h>

Public Member Functions

auto absolute_row_start () const -> u64
 
auto absolute_row_end () const -> u64
 
auto total_rows () const -> usize
 
void clear ()
 Clear the scroll back history.
 
void add_rows (RowGroup &from, usize row_index, usize row_count)
 Add rows to the scroll back buffer.
 
void take_rows (RowGroup &to, u32 desired_cols, usize row_index, usize row_count)
 Remove rows from the scroll back buffer.
 
auto take_rows_for_reflow (RowGroup &to) -> u64
 Take rows so that to.reflow() will produce correct results.
 
auto reflow_visual_rows (u64 absolute_row_start, usize row_count, u32 desired_cols) -> di::Optional< ReflowResult >
 Reflow scroll back for displaying a range of visual lines.
 
auto find_row (u64 row) const -> di::Tuple< u32, RowGroup const & >
 

Detailed Description

Represents the terminal scroll back.

The scroll back is effectively immutable and optimized to minimize the memory needed per cell. Blank cells are not stored but still accessible when iterating over a row.

The scroll back is unaffected by resize operations (until rewrap is supported), so rows can be over or under sized depending on the actual screen size when the scroll back is being rendered.

For efficiency, the scroll back is divided into chunks which target a particular number of cells, and represent a collection of visual terminal lines. The memory limit for the scroll back buffer is specified by the total number of cells allowed, which is used to determine the number of chunks.

Member Function Documentation

◆ absolute_row_end()

auto ttx::terminal::ScrollBack::absolute_row_end ( ) const -> u64
inline

◆ absolute_row_start()

auto ttx::terminal::ScrollBack::absolute_row_start ( ) const -> u64
inline

◆ add_rows()

void ttx::terminal::ScrollBack::add_rows ( RowGroup & from,
usize row_index,
usize row_count )

Add rows to the scroll back buffer.

Parameters
fromRow group to take from
row_indexRow index within the group to take from
row_countNumber of rows to take

The taken rows will be deleted after this call.

◆ clear()

void ttx::terminal::ScrollBack::clear ( )

Clear the scroll back history.

◆ find_row()

auto ttx::terminal::ScrollBack::find_row ( u64 row) const -> di::Tuple<u32, RowGroup const&>

◆ reflow_visual_rows()

auto ttx::terminal::ScrollBack::reflow_visual_rows ( u64 absolute_row_start,
usize row_count,
u32 desired_cols ) -> di::Optional<ReflowResult>

Reflow scroll back for displaying a range of visual lines.

Parameters
absolute_row_startThe absolute for of the first visible row
row_countThe number of visible rows
desired_colsThe desired display width
Returns
The result of the reflow operation (nullopt if no reflow is needed)

Rather than reflow the entire scrollback all at once, reflowing happens lazily during render based on what part of the screen is visible. The scrollback remembers the last size each row group was reflowed to in order to avoid redundant computation. Depending the the absolute row start, it may be required to reflow more than 1 row group, in which case all reflow results are merged together.

◆ take_rows()

void ttx::terminal::ScrollBack::take_rows ( RowGroup & to,
u32 desired_cols,
usize row_index,
usize row_count )

Remove rows from the scroll back buffer.

Parameters
fromRow group to tranfer to
desired_colsNumber of columns to force in the output
row_indexRow index within the group to insert
row_countNumber of rows to take

This function requires: row_count >= total rows in scroll back.

The desired_cols value ensures that the inserted rows will have the correct number of cells per row. The row from scrollback will either be truncated or padded with empty cells to meet this constraint.

◆ take_rows_for_reflow()

auto ttx::terminal::ScrollBack::take_rows_for_reflow ( RowGroup & to) -> u64

Take rows so that to.reflow() will produce correct results.

Parameters
toRow group to transfer to
Returns
The number of rows transferred

This function takes as many rows as necessary from the scrollback so that the last row in the scrollback buffer wasn't overflowed. This means that calling reflow() on the resulting group produces the correct results. Note that because row group boundaries should already be segmented into such boundaries, this function is only best effort. In extreme cases where we have 10 of thousands of lines of next that have overflowed reflow() everything isn't computationally practical, so we impose a limit on how far back we go.

◆ total_rows()

auto ttx::terminal::ScrollBack::total_rows ( ) const -> usize
inline

The documentation for this class was generated from the following files: