feat(term): implement clear() method

Clears all but the bottommost row of the terminal (including scrollback
buffer) and moves the bottommost row to the top.
This commit is contained in:
Leroy Hopson 2024-03-03 22:25:14 +13:00
parent fc03595e29
commit d00a31fb45
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
4 changed files with 82 additions and 12 deletions

View file

@ -75,8 +75,8 @@ void Terminal::_bind_methods()
ClassDB::bind_method(D_METHOD("get_copy_on_selection"), &Terminal::get_copy_on_selection);
ClassDB::add_property("Terminal", PropertyInfo(Variant::BOOL, "copy_on_selection"), "set_copy_on_selection", "get_copy_on_selection");
// Methods.
// Other methods.
ClassDB::bind_method(D_METHOD("clear"), &Terminal::clear);
ClassDB::bind_method(D_METHOD("write", "data"), &Terminal::write);
ClassDB::bind_method(D_METHOD("get_cursor_pos"), &Terminal::get_cursor_pos);
ClassDB::bind_method(D_METHOD("get_cell_size"), &Terminal::get_cell_size);
@ -642,6 +642,19 @@ double Terminal::get_blink_off_time() const
return blink_off_time;
}
void Terminal::clear() {
// Resize the terminal to a single row, forcing content above in to the scrollback buffer.
tsm_screen_resize(screen, cols, 1);
// Clear the scrollback buffer (hence clearing the content that was above).
tsm_screen_clear_sb(screen);
// Resize the screen to its original size.
tsm_screen_resize(screen, cols, rows);
refresh();
}
String Terminal::_copy_screen(ScreenCopyFunction func) {
char *out;
PackedByteArray data;

View file

@ -72,6 +72,8 @@ namespace godot
void set_blink_off_time(const double p_blink_off_time);
double get_blink_off_time() const;
void clear();
String copy_all();
String copy_selection();
void set_copy_on_selection(const bool p_enable);