mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-04-19 14:28:29 +02:00
feat: add get_cursor_pos()
This commit is contained in:
parent
b575895aa7
commit
2392dd7c0d
4 changed files with 28 additions and 0 deletions
|
@ -290,6 +290,8 @@ void Terminal::_register_methods() {
|
||||||
register_method("sb_reset", &Terminal::sb_reset);
|
register_method("sb_reset", &Terminal::sb_reset);
|
||||||
register_method("clear_sb", &Terminal::clear_sb);
|
register_method("clear_sb", &Terminal::clear_sb);
|
||||||
|
|
||||||
|
register_method("get_cursor_pos", &Terminal::get_cursor_pos);
|
||||||
|
|
||||||
register_method("start_selection", &Terminal::start_selection);
|
register_method("start_selection", &Terminal::start_selection);
|
||||||
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);
|
||||||
|
@ -635,6 +637,11 @@ void Terminal::clear_sb() {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 Terminal::get_cursor_pos() {
|
||||||
|
return Vector2(tsm_screen_get_cursor_x(screen),
|
||||||
|
tsm_screen_get_cursor_y(screen));
|
||||||
|
}
|
||||||
|
|
||||||
void Terminal::start_selection(Vector2 position) {
|
void Terminal::start_selection(Vector2 position) {
|
||||||
tsm_screen_selection_start(screen, position.x, position.y);
|
tsm_screen_selection_start(screen, position.x, position.y);
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -60,6 +60,8 @@ public:
|
||||||
void sb_reset();
|
void sb_reset();
|
||||||
void clear_sb();
|
void clear_sb();
|
||||||
|
|
||||||
|
Vector2 get_cursor_pos();
|
||||||
|
|
||||||
void start_selection(Vector2 position);
|
void start_selection(Vector2 position);
|
||||||
void select_to_pointer(Vector2 position);
|
void select_to_pointer(Vector2 position);
|
||||||
void reset_selection();
|
void reset_selection();
|
||||||
|
|
|
@ -71,6 +71,10 @@ func get_rows() -> int:
|
||||||
return _rows
|
return _rows
|
||||||
|
|
||||||
|
|
||||||
|
func get_cursor_pos() -> Vector2:
|
||||||
|
return _native_terminal.get_cursor_pos()
|
||||||
|
|
||||||
|
|
||||||
func write(data) -> void:
|
func write(data) -> void:
|
||||||
assert(
|
assert(
|
||||||
data is PoolByteArray or data is String,
|
data is PoolByteArray or data is String,
|
||||||
|
|
|
@ -33,6 +33,21 @@ func test_bell_cooldown() -> void:
|
||||||
assert_signal_emit_count(terminal, "bell", 2)
|
assert_signal_emit_count(terminal, "bell", 2)
|
||||||
|
|
||||||
|
|
||||||
|
func test_cursor_get_pos_initially_0_0() -> void:
|
||||||
|
assert_eq(terminal.get_cursor_pos(), Vector2(0, 0))
|
||||||
|
|
||||||
|
|
||||||
|
func test_cursor_get_pos_increments_immediately() -> void:
|
||||||
|
terminal.write(" ")
|
||||||
|
assert_eq(terminal.get_cursor_pos(), Vector2(1, 0))
|
||||||
|
|
||||||
|
|
||||||
|
func test_cursor_get_pos_increments_eventually() -> void:
|
||||||
|
terminal.write(" ")
|
||||||
|
yield(yield_to(get_tree(), "idle_frame", 1), YIELD)
|
||||||
|
assert_eq(terminal.get_cursor_pos(), Vector2(1, 0))
|
||||||
|
|
||||||
|
|
||||||
func test_writing_random_data_to_terminal_does_not_crash_application():
|
func test_writing_random_data_to_terminal_does_not_crash_application():
|
||||||
add_child_autofree(preload("res://test/scenes/write_random.tscn").instance())
|
add_child_autofree(preload("res://test/scenes/write_random.tscn").instance())
|
||||||
yield(yield_frames(5, "Writing random data to terminal"), YIELD)
|
yield(yield_frames(5, "Writing random data to terminal"), YIELD)
|
||||||
|
|
Loading…
Add table
Reference in a new issue