diff --git a/addons/godot_xterm/native/src/terminal.cpp b/addons/godot_xterm/native/src/terminal.cpp index 007388d..0a9e5d2 100644 --- a/addons/godot_xterm/native/src/terminal.cpp +++ b/addons/godot_xterm/native/src/terminal.cpp @@ -120,7 +120,7 @@ int Terminal::get_max_scrollback() const return max_scrollback; } -void Terminal::write(Variant data) +String Terminal::write(const Variant data) { PackedByteArray bytes; @@ -133,16 +133,16 @@ void Terminal::write(Variant data) bytes = data; break; default: - ERR_FAIL_MSG("Data must be a String or PackedByteArray."); - return; + ERR_FAIL_V_MSG("", "Data must be a String or PackedByteArray."); } - if (bytes.is_empty()) - return; + if (bytes.is_empty()) return ""; + response.clear(); tsm_vte_input(vte, (char *)bytes.ptr(), bytes.size()); - queue_redraw(); + + return response.get_string_from_utf8(); } void Terminal::_notification(int what) @@ -176,6 +176,13 @@ void Terminal::_notification(int what) void Terminal::_write_cb(tsm_vte *vte, const char *u8, size_t len, void *data) { Terminal *term = static_cast(data); + + if (len > 0) { + size_t old_size = term->response.size(); + term->response.resize(old_size + len); + uint8_t *dest = term->response.ptrw() + old_size; + memcpy(dest, u8, len); + } } int Terminal::_draw_cb(struct tsm_screen *con, diff --git a/addons/godot_xterm/native/src/terminal.h b/addons/godot_xterm/native/src/terminal.h index 509c3e9..9787526 100644 --- a/addons/godot_xterm/native/src/terminal.h +++ b/addons/godot_xterm/native/src/terminal.h @@ -71,7 +71,7 @@ namespace godot void set_inverse_mode(const int mode); int get_inverse_mode() const; - void write(Variant data); + String write(const Variant data); protected: static void _bind_methods(); @@ -93,8 +93,10 @@ namespace godot tsm_vte *vte; tsm_age_t framebuffer_age; + PackedByteArray response; static void _write_cb(struct tsm_vte *vte, const char *u8, size_t len, void *data); + static int _draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch, size_t len, unsigned int width, unsigned int posx, unsigned int posy, const struct tsm_screen_attr *attr,