Change terminal menu option 'Select All' -> 'Copy All'

Adds copy_all() function to terminal node which returns all of the
screen's text.
This commit is contained in:
Leroy Hopson 2021-07-13 22:20:29 +07:00
parent 703eb68f11
commit 97e07093b2
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
4 changed files with 14 additions and 2 deletions

View file

@ -16,7 +16,7 @@ enum TerminalPopupMenuOptions {
NEW_TERMINAL = 0, NEW_TERMINAL = 0,
COPY = 2, COPY = 2,
PASTE = 3, PASTE = 3,
SELECT_ALL = 4, COPY_ALL = 4,
CLEAR = 6, CLEAR = 6,
KILL_TERMINAL = 7, KILL_TERMINAL = 7,
} }
@ -216,6 +216,8 @@ func _on_TerminalPopupMenu_id_pressed(id):
event.unicode = ord(OS.clipboard[i]) event.unicode = ord(OS.clipboard[i])
event.pressed = true event.pressed = true
terminal._gui_input(event) terminal._gui_input(event)
TerminalPopupMenuOptions.COPY_ALL:
OS.clipboard = terminal.copy_all()
TerminalPopupMenuOptions.CLEAR: TerminalPopupMenuOptions.CLEAR:
terminal.clear() terminal.clear()
TerminalPopupMenuOptions.KILL_TERMINAL: TerminalPopupMenuOptions.KILL_TERMINAL:

View file

@ -107,7 +107,7 @@ margin_right = 193.0
margin_bottom = 160.0 margin_bottom = 160.0
size_flags_horizontal = 0 size_flags_horizontal = 0
size_flags_vertical = 0 size_flags_vertical = 0
items = [ "New Terminal", null, 0, false, false, 0, 0, null, "", false, "", null, 0, false, true, 1, 0, null, "", true, "Copy", null, 0, false, false, 2, 0, null, "", false, "Paste", null, 0, false, false, 3, 0, null, "", false, "Select All", null, 0, false, true, 4, 0, null, "", false, "", null, 0, false, false, 5, 0, null, "", true, "Clear", null, 0, false, false, 6, 0, null, "", false, "Kill Terminal", null, 0, false, false, 7, 0, null, "", false ] items = [ "New Terminal", null, 0, false, false, 0, 0, null, "", false, "", null, 0, false, true, 1, 0, null, "", true, "Copy", null, 0, false, false, 2, 0, null, "", false, "Paste", null, 0, false, false, 3, 0, null, "", false, "Copy All", null, 0, false, false, 4, 0, null, "", false, "", null, 0, false, false, 5, 0, null, "", true, "Clear", null, 0, false, false, 6, 0, null, "", false, "Kill Terminal", null, 0, false, false, 7, 0, null, "", false ]
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }

View file

@ -295,6 +295,7 @@ void Terminal::_register_methods() {
register_method("select_to_pointer", &Terminal::select_to_pointer); register_method("select_to_pointer", &Terminal::select_to_pointer);
register_method("reset_selection", &Terminal::reset_selection); register_method("reset_selection", &Terminal::reset_selection);
register_method("copy_selection", &Terminal::copy_selection); register_method("copy_selection", &Terminal::copy_selection);
register_method("copy_all", &Terminal::copy_all);
register_method("_update_theme", &Terminal::update_theme); register_method("_update_theme", &Terminal::update_theme);
register_method("_update_size", &Terminal::update_theme); register_method("_update_size", &Terminal::update_theme);
@ -626,3 +627,11 @@ String Terminal::copy_selection() {
std::free(out); std::free(out);
return result; return result;
} }
String Terminal::copy_all() {
char *out = nullptr;
int len = tsm_screen_copy_all(screen, &out);
String result = String(out);
std::free(out);
return result;
}

View file

@ -64,6 +64,7 @@ public:
void select_to_pointer(Vector2 position); void select_to_pointer(Vector2 position);
void reset_selection(); void reset_selection();
String copy_selection(); String copy_selection();
String copy_all();
enum UpdateMode { enum UpdateMode {
DISABLED, DISABLED,