mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-23 03:05:32 +02:00
feat(term): implement copy_all()
Implements the copy_all() method which copies all text in the screen including text in the scrollback buffer. Includes a fix to an upstream bug in libtsm that resulted in double the number of '\n' characters being copied for each row.
This commit is contained in:
parent
8255d8b3ce
commit
71df1e71bd
5 changed files with 56 additions and 14 deletions
|
@ -68,7 +68,8 @@ void Terminal::_bind_methods()
|
|||
ClassDB::bind_method(D_METHOD("set_blink_off_time", "time"), &Terminal::set_blink_off_time);
|
||||
ClassDB::add_property("Terminal", PropertyInfo(Variant::FLOAT, "blink_off_time"), "set_blink_off_time", "get_blink_off_time");
|
||||
|
||||
// Selection copying.
|
||||
// Copying.
|
||||
ClassDB::bind_method(D_METHOD("copy_all"), &Terminal::copy_all);
|
||||
ClassDB::bind_method(D_METHOD("copy_selection"), &Terminal::copy_selection);
|
||||
ClassDB::bind_method(D_METHOD("set_copy_on_selection", "enabled"), &Terminal::set_copy_on_selection);
|
||||
ClassDB::bind_method(D_METHOD("get_copy_on_selection"), &Terminal::get_copy_on_selection);
|
||||
|
@ -641,15 +642,23 @@ double Terminal::get_blink_off_time() const
|
|||
return blink_off_time;
|
||||
}
|
||||
|
||||
String Terminal::_copy_screen(ScreenCopyFunction func) {
|
||||
char *out;
|
||||
PackedByteArray data;
|
||||
|
||||
data.resize(func(screen, &out));
|
||||
memcpy(data.ptrw(), out, data.size());
|
||||
std::free(out);
|
||||
|
||||
return data.get_string_from_utf8();
|
||||
}
|
||||
|
||||
String Terminal::copy_all() {
|
||||
return _copy_screen(&tsm_screen_copy_all);
|
||||
}
|
||||
|
||||
String Terminal::copy_selection() {
|
||||
char *out;
|
||||
PackedByteArray data;
|
||||
|
||||
data.resize(tsm_screen_selection_copy(screen, &out));
|
||||
memcpy(data.ptrw(), out, data.size());
|
||||
std::free(out);
|
||||
|
||||
return data.get_string_from_utf8();
|
||||
return _copy_screen(&tsm_screen_selection_copy);
|
||||
}
|
||||
|
||||
void Terminal::set_copy_on_selection(const bool p_enabled) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue