ttx 0.1.0
Loading...
Searching...
No Matches
scroll_back.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/container/ring/prelude.h"
6
7namespace ttx::terminal {
24 constexpr static auto target_cells_per_group = usize(di::NumericLimits<u16>::max / 2);
25
26 constexpr static auto max_cells_per_group = usize(di::NumericLimits<u16>::max);
27
28 // TODO: make this configurable.
29 constexpr static auto max_cells = usize(target_cells_per_group * 100);
30
31 constexpr static auto max_groups = di::divide_round_up(max_cells, target_cells_per_group);
32
33 struct Group {
34 RowGroup group;
35 usize cell_count { 0 };
36 di::Optional<u32> last_reflowed_to;
37 };
38
39public:
40 auto absolute_row_start() const -> u64 { return m_absolute_row_start; }
41 auto absolute_row_end() const -> u64 { return m_absolute_row_start + total_rows(); }
42 auto total_rows() const -> usize { return m_total_rows; }
43
45 void clear();
46
54 void add_rows(RowGroup& from, usize row_index, usize row_count);
55
68 void take_rows(RowGroup& to, u32 desired_cols, usize row_index, usize row_count);
69
83 auto take_rows_for_reflow(RowGroup& to) -> u64;
84
98 auto reflow_visual_rows(u64 absolute_row_start, usize row_count, u32 desired_cols) -> di::Optional<ReflowResult>;
99
100 auto find_row(u64 row) const -> di::Tuple<u32, RowGroup const&>;
101
102private:
103 auto get_target_cells_per_group(bool last_row_overflow) const {
104 // We use a larger threshold when the last row in the group has overflow set.
105 // This is done to try and only break row groups on boundaries which preserve
106 // logical rows.
107 return last_row_overflow ? max_cells_per_group : target_cells_per_group;
108 }
109
110 auto find_row_group(u64 row) -> di::Tuple<u32, u64, Group&>;
111 auto is_last_group_full() const -> bool;
112 auto add_group() -> Group&;
113
114 di::Ring<Group> m_groups;
115 usize m_total_rows { 0 };
116 u64 m_absolute_row_start { 0 };
117};
118}
Represents a group of terminal rows.
Definition row_group.h:24
Represents the terminal scroll back.
Definition scroll_back.h:23
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.
Definition scroll_back.cpp:84
auto take_rows_for_reflow(RowGroup &to) -> u64
Take rows so that to.reflow() will produce correct results.
Definition scroll_back.cpp:63
auto find_row(u64 row) const -> di::Tuple< u32, RowGroup const & >
Definition scroll_back.cpp:114
auto absolute_row_start() const -> u64
Definition scroll_back.h:40
auto total_rows() const -> usize
Definition scroll_back.h:42
auto absolute_row_end() const -> u64
Definition scroll_back.h:41
void add_rows(RowGroup &from, usize row_index, usize row_count)
Add rows to the scroll back buffer.
Definition scroll_back.cpp:6
void clear()
Clear the scroll back history.
Definition scroll_back.cpp:137
void take_rows(RowGroup &to, u32 desired_cols, usize row_index, usize row_count)
Remove rows from the scroll back buffer.
Definition scroll_back.cpp:40
Definition absolute_position.h:6