3#include "di/container/ring/ring.h"
4#include "di/io/vector_writer.h"
5#include "dius/sync_file.h"
28 mutable bool dirty : 1 {
true };
31 using Row = di::Vector<Cell>;
33 explicit Terminal(dius::SyncFile& psuedo_terminal) : m_psuedo_terminal(psuedo_terminal) {}
36 auto result =
Terminal(m_psuedo_terminal);
37 result.m_rows = di::clone(m_rows);
38 result.m_row_count = m_row_count;
39 result.m_col_count = m_col_count;
40 result.m_xpixels = m_xpixels;
41 result.m_ypixels = m_ypixels;
42 result.m_col_count = m_col_count;
43 result.m_available_rows_in_display = m_available_rows_in_display;
44 result.m_available_cols_in_display = m_available_cols_in_display;
45 result.m_available_xpixels_in_display = m_available_xpixels_in_display;
46 result.m_available_ypixels_in_display = m_available_ypixels_in_display;
47 result.m_80_col_mode = m_80_col_mode;
48 result.m_132_col_mode = m_132_col_mode;
49 result.m_allow_80_132_col_mode = m_allow_80_132_col_mode;
50 result.m_force_terminal_size = m_force_terminal_size;
51 result.m_allow_force_terminal_size = m_allow_force_terminal_size;
53 result.m_tab_stops = di::clone(m_tab_stops);
54 result.m_cursor_row = m_cursor_row;
55 result.m_cursor_col = m_cursor_col;
56 result.m_cursor_style = m_cursor_style;
57 result.m_saved_cursor_row = m_saved_cursor_row;
58 result.m_saved_cursor_col = m_saved_cursor_col;
59 result.m_cursor_hidden = m_cursor_hidden;
60 result.m_disable_drawing = m_disable_drawing;
61 result.m_autowrap_mode = m_autowrap_mode;
62 result.m_x_overflow = m_x_overflow;
63 result.m_origin_mode = m_origin_mode;
65 result.m_application_cursor_keys_mode = m_application_cursor_keys_mode;
66 result.m_key_reporting_flags = m_key_reporting_flags;
67 result.m_key_reporting_flags_stack = di::clone(m_key_reporting_flags_stack);
69 result.m_alternate_scroll_mode = m_alternate_scroll_mode;
70 result.m_mouse_protocol = m_mouse_protocol;
71 result.m_mouse_encoding = m_mouse_encoding;
72 result.m_focus_event_mode = m_focus_event_mode;
74 result.m_bracketed_paste_mode = m_bracketed_paste_mode;
76 result.m_current_graphics_rendition = m_current_graphics_rendition;
78 result.m_rows_below = di::clone(m_rows_below);
79 result.m_rows_above = di::clone(m_rows_above);
80 result.m_scroll_start = m_scroll_start;
81 result.m_scroll_end = m_scroll_end;
104 auto total_rows() const -> u32 {
return m_rows_above.size() + m_rows.size() + m_rows_below.size(); }
105 auto row_offset() const -> u32 {
return m_rows_above.size(); }
108 auto size() const -> dius::tty::WindowSize {
return { m_row_count, m_col_count, m_xpixels, m_ypixels }; }
112 return { m_available_rows_in_display, m_available_cols_in_display, m_available_xpixels_in_display,
113 m_available_ypixels_in_display };
132 auto rows() const -> di::Vector<
Row> const& {
return m_rows; }
137 auto outgoing_events() -> di::Vector<TerminalEvent> {
return di::move(m_outgoing_events); }
143 void on_parser_result(
DCS const& dcs);
144 void on_parser_result(
OSC const& osc);
145 void on_parser_result(
APC const& apc);
146 void on_parser_result(
CSI const& csi);
147 void on_parser_result(
Escape const& escape);
150 void resize(dius::tty::WindowSize
const& window_size);
152 void put_char(u32 row, u32 col, c32 c);
153 void put_char(c32 c);
156 m_saved_cursor_row = m_cursor_row;
157 m_saved_cursor_col = m_cursor_col;
160 m_cursor_row = m_saved_cursor_row;
161 m_cursor_col = m_saved_cursor_col;
164 void set_cursor(u32 row, u32 col);
166 auto min_row_inclusive() const -> u32 {
168 return m_scroll_start;
172 auto min_col_inclusive() const -> u32 {
return 0; }
174 auto max_row_inclusive() const -> u32 {
178 return m_row_count - 1;
180 auto max_col_inclusive() const -> u32 {
return m_col_count - 1; }
182 auto translate_row(u32 row)
const -> u32 {
184 return row + m_scroll_start - 1;
188 auto translate_col(u32 col)
const -> u32 {
return col - 1; }
190 void clear_below_cursor(
char ch =
' ');
191 void clear_above_cursor(
char ch =
' ');
192 void clear(
char ch =
' ');
193 void clear_row(u32 row,
char ch =
' ');
194 void clear_row_until(u32 row, u32 end_col,
char ch =
' ');
195 void clear_row_to_end(u32 row, u32 start_col,
char ch =
' ');
197 auto state_as_escape_sequences_internal(di::VectorWriter<>& writer)
const;
199 void set_use_alternate_screen_buffer(
bool b);
217 void dcs_decrqss(Params
const& params, di::StringView data);
219 void osc_52(di::StringView data);
221 void csi_ich(Params
const& params);
222 void csi_cuu(Params
const& params);
223 void csi_cud(Params
const& params);
224 void csi_cuf(Params
const& params);
225 void csi_cub(Params
const& params);
226 void csi_cup(Params
const& params);
227 void csi_cha(Params
const& params);
228 void csi_ed(Params
const& params);
229 void csi_el(Params
const& params);
230 void csi_il(Params
const& params);
231 void csi_dl(Params
const& params);
232 void csi_dch(Params
const& params);
233 void csi_su(Params
const& params);
234 void csi_sd(Params
const& params);
235 void csi_ech(Params
const& params);
236 void csi_rep(Params
const& params);
237 void csi_da1(Params
const& params);
238 void csi_da2(Params
const& params);
239 void csi_da3(Params
const& params);
240 void csi_vpa(Params
const& params);
241 void csi_hvp(Params
const& params);
242 void csi_tbc(Params
const& params);
243 void csi_decset(Params
const& params);
244 void csi_decrst(Params
const& params);
245 void csi_decrqm(Params
const& params);
246 void csi_decscusr(Params
const& params);
247 void csi_sgr(Params
const& params);
248 void csi_dsr(Params
const& params);
249 void csi_decstbm(Params
const& params);
250 void csi_scosc(Params
const& params);
251 void csi_scorc(Params
const& params);
252 void csi_xtwinops(Params
const& params);
254 void csi_set_key_reporting_flags(Params
const& params);
255 void csi_get_key_reporting_flags(Params
const& params);
256 void csi_push_key_reporting_flags(Params
const& params);
257 void csi_pop_key_reporting_flags(Params
const& params);
259 di::Vector<Row> m_rows;
260 u32 m_row_count { 0 };
261 u32 m_col_count { 0 };
264 u32 m_available_rows_in_display { 0 };
265 u32 m_available_cols_in_display { 0 };
266 u32 m_available_xpixels_in_display { 0 };
267 u32 m_available_ypixels_in_display { 0 };
268 bool m_80_col_mode {
false };
269 bool m_132_col_mode {
false };
270 bool m_allow_80_132_col_mode {
false };
271 bool m_force_terminal_size {
false };
272 bool m_allow_force_terminal_size {
false };
274 di::Vector<u32> m_tab_stops;
275 u32 m_cursor_row { 0 };
276 u32 m_cursor_col { 0 };
277 u32 m_saved_cursor_row { 0 };
278 u32 m_saved_cursor_col { 0 };
280 bool m_cursor_hidden {
false };
281 bool m_disable_drawing {
false };
282 bool m_autowrap_mode {
true };
283 bool m_x_overflow {
false };
284 bool m_origin_mode {
false };
288 di::Ring<KeyReportingFlags> m_key_reporting_flags_stack;
297 GraphicsRendition m_current_graphics_rendition;
299 di::Vector<Row> m_rows_below;
300 di::Vector<Row> m_rows_above;
301 u32 m_scroll_start { 0 };
302 u32 m_scroll_end { 0 };
304 di::Vector<TerminalEvent> m_outgoing_events;
306 di::Box<Terminal> m_save_state;
308 dius::SyncFile& m_psuedo_terminal;
void scroll_to_bottom()
Definition terminal.cpp:1303
auto key_reporting_flags() const -> KeyReportingFlags
Definition terminal.h:120
void invalidate_all()
Definition terminal.cpp:1083
auto cursor_style() const -> CursorStyle
Definition terminal.h:95
void set_visible_size(dius::tty::WindowSize const &window_size)
Definition terminal.cpp:1033
auto mouse_encoding() const -> MouseEncoding
Definition terminal.h:124
auto cursor_col() const -> u32
Definition terminal.h:92
auto row_at_scroll_relative_offset(u32 offset) const -> Row const &
Definition terminal.cpp:1183
auto bracked_paste_mode() const -> BracketedPasteMode
Definition terminal.h:130
void reset_mouse_reporting()
Definition terminal.h:128
auto scroll_relative_offset(u32 display_row) const -> u32
Definition terminal.cpp:1173
auto outgoing_events() -> di::Vector< TerminalEvent >
Definition terminal.h:137
void set_allow_force_terminal_size(bool b=true)
Definition terminal.h:139
void on_parser_results(di::Span< ParserResult const > results)
Definition terminal.cpp:21
auto should_display_cursor_at_position(u32 r, u32 c) const -> bool
Definition terminal.cpp:1157
auto col_count() const -> u32
Definition terminal.h:107
auto visible_size() const -> dius::tty::WindowSize
Definition terminal.h:111
auto focus_event_mode() const -> FocusEventMode
Definition terminal.h:126
auto mouse_protocol() const -> MouseProtocol
Definition terminal.h:123
void scroll_up()
Definition terminal.cpp:1238
auto total_rows() const -> u32
Definition terminal.h:104
auto row_count() const -> u32
Definition terminal.h:106
void scroll_down_if_needed()
Definition terminal.cpp:1281
void scroll_down()
Definition terminal.cpp:1249
auto cursor_row() const -> u32
Definition terminal.h:91
Terminal(dius::SyncFile &psuedo_terminal)
Definition terminal.h:33
auto rows() const -> di::Vector< Row > const &
Definition terminal.h:132
auto cursor_hidden() const -> bool
Definition terminal.h:93
auto alternate_scroll_mode() const -> AlternateScrollMode
Definition terminal.h:122
auto row_offset() const -> u32
Definition terminal.h:105
di::Vector< Cell > Row
Definition terminal.h:31
auto clone() const -> Terminal
Definition terminal.h:35
auto application_cursor_keys_mode() const -> ApplicationCursorKeysMode
Definition terminal.h:119
auto state_as_escape_sequences() const -> di::String
Definition terminal.cpp:1505
auto in_alternate_screen_buffer() const -> bool
Definition terminal.h:125
void scroll_up_if_needed()
Definition terminal.cpp:1260
auto size() const -> dius::tty::WindowSize
Definition terminal.h:108
auto allowed_to_draw() const -> bool
Definition terminal.h:98
Definition test_graphics_rendition.cpp:7
Definition cursor_style.h:5
MouseEncoding
Definition mouse_event_io.h:44
@ X10
Definition mouse_event_io.h:45
KeyReportingFlags
Definition key_event_io.h:27
@ None
Definition key_event_io.h:28
di::Variant< PrintableCharacter, DCS, OSC, APC, CSI, Escape, ControlCharacter > ParserResult
Definition escape_sequence_parser.h:92
AlternateScrollMode
Definition mouse_event_io.h:14
@ Disabled
Definition mouse_event_io.h:15
auto resize(ResizeDirection direction, i32 amount_in_cells) -> Action
Definition actions.cpp:41
CursorStyle
Definition cursor_style.h:6
@ SteadyBlock
Definition cursor_style.h:8
di::Variant< SetClipboard > TerminalEvent
Definition terminal.h:21
MouseProtocol
Definition mouse_event_io.h:27
@ None
Definition mouse_event_io.h:28
BracketedPasteMode
Definition paste_event_io.h:11
ApplicationCursorKeysMode
Definition key_event_io.h:14
@ Disabled
Definition key_event_io.h:15
FocusEventMode
Definition focus_event_io.h:10
@ Disabled
Definition focus_event_io.h:11
Definition escape_sequence_parser.h:45
Definition escape_sequence_parser.h:55
Definition escape_sequence_parser.h:80
Definition escape_sequence_parser.h:21
Definition escape_sequence_parser.h:68
Definition graphics_rendition.h:103
Definition escape_sequence_parser.h:34
Definition escape_sequence_parser.h:11
di::Vector< byte > data
Definition terminal.h:18
c32 ch
Definition terminal.h:26
bool dirty
Definition terminal.h:28