mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-13 22:10:25 +01:00
feat(term): implement data_sent signal
This commit is contained in:
parent
14288352fd
commit
988788fc68
2 changed files with 18 additions and 0 deletions
|
@ -25,6 +25,7 @@ using namespace godot;
|
||||||
|
|
||||||
void Terminal::_bind_methods()
|
void Terminal::_bind_methods()
|
||||||
{
|
{
|
||||||
|
ADD_SIGNAL(MethodInfo("data_sent", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data")));
|
||||||
ADD_SIGNAL(MethodInfo("key_pressed", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data"), PropertyInfo(Variant::OBJECT, "event")));
|
ADD_SIGNAL(MethodInfo("key_pressed", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data"), PropertyInfo(Variant::OBJECT, "event")));
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_cols"), &Terminal::get_cols);
|
ClassDB::bind_method(D_METHOD("get_cols"), &Terminal::get_cols);
|
||||||
|
@ -229,6 +230,8 @@ void Terminal::_write_cb(tsm_vte *vte, const char *u8, size_t len, void *data)
|
||||||
term->emit_signal("key_pressed", data.get_string_from_utf8(), term->last_input_event_key);
|
term->emit_signal("key_pressed", data.get_string_from_utf8(), term->last_input_event_key);
|
||||||
term->last_input_event_key.unref();
|
term->last_input_event_key.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
term->emit_signal("data_sent", data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ var terminal: Terminal
|
||||||
func before_each():
|
func before_each():
|
||||||
terminal = Terminal.new()
|
terminal = Terminal.new()
|
||||||
terminal.size = Vector2(400, 200)
|
terminal.size = Vector2(400, 200)
|
||||||
|
watch_signals(terminal)
|
||||||
add_child_autofree(terminal)
|
add_child_autofree(terminal)
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,3 +77,17 @@ class TestWrite:
|
||||||
func test_returns_response_to_multiple_queries_among_other_data():
|
func test_returns_response_to_multiple_queries_among_other_data():
|
||||||
var response = terminal.write("hello\r\nworld\u001b[6nother\r\ndata\u001b[5ntest")
|
var response = terminal.write("hello\r\nworld\u001b[6nother\r\ndata\u001b[5ntest")
|
||||||
assert_eq(response, "\u001b[2;6R\u001b[0n")
|
assert_eq(response, "\u001b[2;6R\u001b[0n")
|
||||||
|
|
||||||
|
func test_data_sent_emitted_on_query():
|
||||||
|
terminal.write("\u001b[6n")
|
||||||
|
assert_signal_emitted(terminal, "data_sent")
|
||||||
|
|
||||||
|
func test_data_sent_emitted_with_response():
|
||||||
|
terminal.write("\u001b[6n")
|
||||||
|
assert_signal_emitted_with_parameters(
|
||||||
|
terminal, "data_sent", ["\u001b[1;1R".to_utf8_buffer()]
|
||||||
|
)
|
||||||
|
|
||||||
|
func test_data_sent_not_emitted_when_empty_string_written():
|
||||||
|
terminal.write("")
|
||||||
|
assert_signal_emit_count(terminal, "data_sent", 0)
|
||||||
|
|
Loading…
Reference in a new issue