mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-04 20:24:23 +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) {
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include<map>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include <godot_cpp/classes/control.hpp>
|
||||
#include <godot_cpp/classes/image_texture.hpp>
|
||||
|
@ -71,6 +72,7 @@ namespace godot
|
|||
void set_blink_off_time(const double p_blink_off_time);
|
||||
double get_blink_off_time() const;
|
||||
|
||||
String copy_all();
|
||||
String copy_selection();
|
||||
void set_copy_on_selection(const bool p_enable);
|
||||
bool get_copy_on_selection() const;
|
||||
|
@ -170,6 +172,9 @@ namespace godot
|
|||
Timer *selection_timer;
|
||||
void _handle_selection(Ref<InputEventMouse> event);
|
||||
void _on_selection_held();
|
||||
|
||||
typedef std::function<int(struct tsm_screen*, char**)> ScreenCopyFunction;
|
||||
String _copy_screen(ScreenCopyFunction func);
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
|
2
addons/godot_xterm/native/thirdparty/libtsm
vendored
2
addons/godot_xterm/native/thirdparty/libtsm
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 2131b47acdee1088a78ca922ca96361d6182a03f
|
||||
Subproject commit fa5021916aa8f4e292ae6dbbf9fc874ae517c3a3
|
Loading…
Add table
Add a link
Reference in a new issue