Add clear and sb_reset

Clearing the terminal removes all lines in the scrollback buffer except
for the most recent.

With sb_reset, the terminal will return the scrollback buffer to the
bottom when the user starts typing if they have previously scrolled up.
This commit is contained in:
Leroy Hopson 2021-07-13 06:27:20 +07:00
parent ebb527cb8b
commit e8c27f2796
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
5 changed files with 40 additions and 12 deletions

View file

@ -288,6 +288,8 @@ void Terminal::_register_methods() {
register_method("sb_up", &Terminal::sb_up);
register_method("sb_down", &Terminal::sb_down);
register_method("sb_reset", &Terminal::sb_reset);
register_method("clear_sb", &Terminal::clear_sb);
register_method("start_selection", &Terminal::start_selection);
register_method("select_to_pointer", &Terminal::select_to_pointer);
@ -567,7 +569,7 @@ void Terminal::update_size() {
cell_size = fontref->get_string_size("W");
rows = std::max(2, (int)floor(get_rect().size.y / cell_size.y));
rows = std::max(1, (int)floor(get_rect().size.y / cell_size.y));
cols = std::max(1, (int)floor(get_rect().size.x / cell_size.x));
tsm_screen_resize(screen, cols, rows);
@ -592,6 +594,16 @@ void Terminal::sb_down(int num) {
update();
}
void Terminal::sb_reset() {
tsm_screen_sb_reset(screen);
update();
}
void Terminal::clear_sb() {
tsm_screen_clear_sb(screen);
update();
}
void Terminal::start_selection(Vector2 position) {
tsm_screen_selection_start(screen, position.x, position.y);
update();
@ -613,4 +625,4 @@ String Terminal::copy_selection() {
String result = String(out);
std::free(out);
return result;
}
}

View file

@ -57,6 +57,8 @@ public:
void sb_up(int num);
void sb_down(int num);
void sb_reset();
void clear_sb();
void start_selection(Vector2 position);
void select_to_pointer(Vector2 position);