mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Return terminal responses from write method
Updates the `write()` method to return a String containing any responses from the terminal. For example, these could be responses to a cursor position request such as "\u001b[6n".
This commit is contained in:
parent
9fde38045a
commit
07687e2cd8
2 changed files with 16 additions and 7 deletions
|
@ -120,7 +120,7 @@ int Terminal::get_max_scrollback() const
|
||||||
return max_scrollback;
|
return max_scrollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::write(Variant data)
|
String Terminal::write(const Variant data)
|
||||||
{
|
{
|
||||||
PackedByteArray bytes;
|
PackedByteArray bytes;
|
||||||
|
|
||||||
|
@ -133,16 +133,16 @@ void Terminal::write(Variant data)
|
||||||
bytes = data;
|
bytes = data;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERR_FAIL_MSG("Data must be a String or PackedByteArray.");
|
ERR_FAIL_V_MSG("", "Data must be a String or PackedByteArray.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes.is_empty())
|
if (bytes.is_empty()) return "";
|
||||||
return;
|
|
||||||
|
|
||||||
|
response.clear();
|
||||||
tsm_vte_input(vte, (char *)bytes.ptr(), bytes.size());
|
tsm_vte_input(vte, (char *)bytes.ptr(), bytes.size());
|
||||||
|
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
|
|
||||||
|
return response.get_string_from_utf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::_notification(int what)
|
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)
|
void Terminal::_write_cb(tsm_vte *vte, const char *u8, size_t len, void *data)
|
||||||
{
|
{
|
||||||
Terminal *term = static_cast<Terminal *>(data);
|
Terminal *term = static_cast<Terminal *>(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,
|
int Terminal::_draw_cb(struct tsm_screen *con,
|
||||||
|
|
|
@ -71,7 +71,7 @@ namespace godot
|
||||||
void set_inverse_mode(const int mode);
|
void set_inverse_mode(const int mode);
|
||||||
int get_inverse_mode() const;
|
int get_inverse_mode() const;
|
||||||
|
|
||||||
void write(Variant data);
|
String write(const Variant data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
@ -93,8 +93,10 @@ namespace godot
|
||||||
tsm_vte *vte;
|
tsm_vte *vte;
|
||||||
tsm_age_t framebuffer_age;
|
tsm_age_t framebuffer_age;
|
||||||
|
|
||||||
|
PackedByteArray response;
|
||||||
static void _write_cb(struct tsm_vte *vte, const char *u8, size_t len,
|
static void _write_cb(struct tsm_vte *vte, const char *u8, size_t len,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
static int _draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch,
|
static int _draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch,
|
||||||
size_t len, unsigned int width, unsigned int posx,
|
size_t len, unsigned int width, unsigned int posx,
|
||||||
unsigned int posy, const struct tsm_screen_attr *attr,
|
unsigned int posy, const struct tsm_screen_attr *attr,
|
||||||
|
|
Loading…
Reference in a new issue