mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-03 20:14:22 +02:00
Godot 4 automatic changes
This commit is contained in:
parent
8b5caafbc7
commit
cdbf3f2adc
75 changed files with 1034 additions and 952 deletions
|
@ -7,7 +7,7 @@ var terminal: Terminal
|
|||
|
||||
func before_each():
|
||||
terminal = Terminal.new()
|
||||
terminal.rect_size = Vector2(400, 200)
|
||||
terminal.size = Vector2(400, 200)
|
||||
add_child_autofree(terminal)
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ func test_bell() -> void:
|
|||
terminal.write("\a")
|
||||
terminal.write("\u0007")
|
||||
terminal.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
|
||||
yield(yield_to(terminal, "bell", 5), YIELD)
|
||||
await yield_to(terminal, "bell", 5).YIELD
|
||||
assert_signal_emit_count(terminal, "bell", 5)
|
||||
|
||||
|
||||
|
@ -27,15 +27,15 @@ func test_bell_cooldown() -> void:
|
|||
terminal.bell_cooldown = 0.5
|
||||
terminal.write("\a")
|
||||
terminal.write("\a")
|
||||
yield(yield_for(1), YIELD)
|
||||
await yield_for(1).YIELD
|
||||
terminal.write("\a")
|
||||
yield(yield_to(terminal, "bell", 5), YIELD)
|
||||
await yield_to(terminal, "bell", 5).YIELD
|
||||
assert_signal_emit_count(terminal, "bell", 2)
|
||||
|
||||
|
||||
func test_writing_random_data_to_terminal_does_not_crash_application():
|
||||
add_child_autofree(preload("res://test/scenes/write_random.tscn").instance())
|
||||
yield(yield_frames(5, "Writing random data to terminal"), YIELD)
|
||||
add_child_autofree(preload("res://test/scenes/write_random.tscn").instantiate())
|
||||
await yield_frames(5, "Writing random data to terminal").YIELD
|
||||
assert_true(true, "Expected no crash when writing random data to terminal.")
|
||||
|
||||
|
||||
|
@ -71,16 +71,16 @@ class TestTheme:
|
|||
|
||||
func _get_pixelv(src: Vector2) -> Color:
|
||||
var screen := get_tree().root.get_texture().get_data()
|
||||
screen.lock()
|
||||
false # screen.lock() # TODOConverter40, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed
|
||||
screen.flip_y()
|
||||
var pixel := screen.get_pixelv(src)
|
||||
screen.unlock()
|
||||
false # screen.unlock() # TODOConverter40, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed
|
||||
return pixel
|
||||
|
||||
func _check_colors(theme: Theme):
|
||||
var cell_size := Vector2(
|
||||
int(terminal.rect_size.x / terminal.get_cols()),
|
||||
int(terminal.rect_size.y / terminal.get_rows())
|
||||
int(terminal.size.x / terminal.get_cols()),
|
||||
int(terminal.size.y / terminal.get_rows())
|
||||
)
|
||||
var src := cell_size / 2
|
||||
|
||||
|
@ -96,61 +96,61 @@ class TestTheme:
|
|||
src += Vector2(cell_size.x, 0)
|
||||
|
||||
func before_each():
|
||||
terminal = autofree(TestScene.instance())
|
||||
yield(yield_frames(1), YIELD)
|
||||
terminal = autofree(TestScene.instantiate())
|
||||
await yield_frames(1).YIELD
|
||||
|
||||
func test_terminal_display_colors_from_default_theme():
|
||||
terminal.theme = null
|
||||
add_child(terminal)
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
_check_colors(default_theme)
|
||||
|
||||
func test_terminal_displays_colors_from_theme():
|
||||
terminal.theme = alt_theme
|
||||
add_child(terminal)
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
_check_colors(alt_theme)
|
||||
|
||||
func test_visible_characters_still_displayed_after_resize_with_default_theme():
|
||||
terminal.theme = null
|
||||
add_child(terminal)
|
||||
yield(yield_frames(1), YIELD)
|
||||
await yield_frames(1).YIELD
|
||||
OS.window_size += Vector2(1, 0)
|
||||
yield(yield_to(terminal, "size_changed", 5), YIELD)
|
||||
await yield_to(terminal, "size_changed", 5).YIELD
|
||||
_check_colors(default_theme)
|
||||
|
||||
func test_visible_characters_still_displayed_after_resize_with_custom_theme():
|
||||
# Issue 57: https://github.com/lihop/godot-xterm/issues/57
|
||||
terminal.theme = alt_theme
|
||||
add_child(terminal)
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
OS.window_size += Vector2(1, 0)
|
||||
yield(yield_to(terminal, "size_changed", 5), YIELD)
|
||||
await yield_to(terminal, "size_changed", 5).YIELD
|
||||
_check_colors(alt_theme)
|
||||
|
||||
func test_updates_colors_after_theme_set():
|
||||
# Issue 58: https://github.com/lihop/godot-xterm/issues/58
|
||||
terminal.theme = null
|
||||
add_child(terminal)
|
||||
yield(yield_frames(1), YIELD)
|
||||
await yield_frames(1).YIELD
|
||||
terminal.theme = alt_theme
|
||||
yield(yield_to(terminal, "theme_changed", 50), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 50).YIELD
|
||||
_check_colors(alt_theme)
|
||||
|
||||
func test_updates_colors_after_theme_unset():
|
||||
# Issue 58: https://github.com/lihop/godot-xterm/issues/58
|
||||
terminal.theme = alt_theme
|
||||
add_child(terminal)
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
terminal.theme = null
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
_check_colors(default_theme)
|
||||
|
||||
func test_updates_colors_after_theme_changed():
|
||||
# Issue 58: https://github.com/lihop/godot-xterm/issues/58
|
||||
terminal.theme = alt_theme
|
||||
add_child(terminal)
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
terminal.theme = default_theme
|
||||
yield(yield_to(terminal, "theme_changed", 5), YIELD)
|
||||
await yield_to(terminal, "theme_changed", 5).YIELD
|
||||
_check_colors(default_theme)
|
||||
|
|
|
@ -26,8 +26,8 @@ func test_fork_succeeds():
|
|||
|
||||
func test_fork_has_output():
|
||||
pty.call_deferred("fork", "exit")
|
||||
yield(yield_to(pty, "data_received", 1), YIELD)
|
||||
var expected := PoolByteArray(
|
||||
await yield_to(pty, "data_received", 1).YIELD
|
||||
var expected := PackedByteArray(
|
||||
[
|
||||
101,
|
||||
120,
|
||||
|
@ -124,20 +124,20 @@ func test_closes_pty_on_exit():
|
|||
pty.fork("sleep", ["1000"])
|
||||
remove_child(pty)
|
||||
pty.free()
|
||||
yield(yield_for(1), YIELD)
|
||||
await yield_for(1).YIELD
|
||||
var new_num_pts = helper._get_pts().size()
|
||||
assert_eq(new_num_pts, num_pts)
|
||||
|
||||
|
||||
func test_emits_exited_signal_when_child_process_exits():
|
||||
pty.call_deferred("fork", "exit")
|
||||
yield(yield_to(pty, "exited", 1), YIELD)
|
||||
await yield_to(pty, "exited", 1).YIELD
|
||||
assert_signal_emitted(pty, "exited")
|
||||
|
||||
|
||||
class Helper:
|
||||
static func _get_pts() -> Array:
|
||||
assert(false, "Abstract method")
|
||||
assert(false) #,"Abstract method")
|
||||
return []
|
||||
|
||||
static func _get_winsize(fd: int) -> Dictionary:
|
||||
|
@ -161,9 +161,9 @@ class Helper:
|
|||
true,
|
||||
output
|
||||
)
|
||||
assert(exit_code == 0, "Failed to run python command for this test.")
|
||||
assert(exit_code == 0) #,"Failed to run python command for this test.")
|
||||
|
||||
var size = str2var("Vector2" + output[0].strip_edges())
|
||||
var size = str_to_var("Vector2" + output[0].strip_edges())
|
||||
return {rows = int(size.x), cols = int(size.y)}
|
||||
|
||||
|
||||
|
@ -186,7 +186,7 @@ class TestPTYSize:
|
|||
regex.compile(".*rows (?<rows>[0-9]+).*columns (?<columns>[0-9]+).*")
|
||||
|
||||
func before_each():
|
||||
scene = add_child_autofree(preload("res://test/scenes/pty_and_terminal.tscn").instance())
|
||||
scene = add_child_autofree(preload("res://test/scenes/pty_and_terminal.tscn").instantiate())
|
||||
|
||||
func test_correct_stty_reports_correct_size():
|
||||
for s in [
|
||||
|
@ -198,14 +198,14 @@ class TestPTYSize:
|
|||
"PTYCousinAbove2",
|
||||
"PTYCousinBelow2"
|
||||
]:
|
||||
pty = scene.get_node(s).find_node("PTY")
|
||||
terminal = scene.get_node(s).find_node("Terminal")
|
||||
pty = scene.get_node(s).find_child("PTY")
|
||||
terminal = scene.get_node(s).find_child("Terminal")
|
||||
|
||||
pty.call_deferred("fork", OS.get_environment("SHELL"))
|
||||
pty.call_deferred("write", "stty -a | head -n1\n")
|
||||
var output := ""
|
||||
while not "rows" in output and not "columns" in output:
|
||||
output = (yield(pty, "data_received")).get_string_from_utf8()
|
||||
output = (await pty.data_received).get_string_from_utf8()
|
||||
var regex_match = regex.search(output)
|
||||
var stty_rows = int(regex_match.get_string("rows"))
|
||||
var stty_cols = int(regex_match.get_string("columns"))
|
||||
|
@ -228,14 +228,14 @@ class LinuxHelper:
|
|||
static func _get_pts() -> Array:
|
||||
var dir := Directory.new()
|
||||
|
||||
if dir.open("/dev/pts") != OK or dir.list_dir_begin(true, true) != OK:
|
||||
assert(false, "Could not open /dev/pts.")
|
||||
if dir.open("/dev/pts") != OK or dir.list_dir_begin() != OK:# TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
|
||||
assert(false) #,"Could not open /dev/pts.")
|
||||
|
||||
var pts := []
|
||||
var file_name: String = dir.get_next()
|
||||
|
||||
while file_name != "":
|
||||
if file_name.is_valid_integer():
|
||||
if file_name.is_valid_int():
|
||||
pts.append("/dev/pts/%s" % file_name)
|
||||
file_name = dir.get_next()
|
||||
|
||||
|
@ -249,5 +249,5 @@ class MacOSHelper:
|
|||
# TODO: Implement for macOS.
|
||||
# On macOS there is no /dev/pts directory, rather new ptys are created
|
||||
# under /dev/ttysXYZ.
|
||||
assert(false, "Not implemented")
|
||||
assert(false) #,"Not implemented")
|
||||
return []
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
extends Control
|
||||
|
||||
onready var terminal = $Terminal
|
||||
@onready var terminal = $Terminal
|
||||
|
||||
|
||||
func _ready():
|
||||
print("terminal size; rows %d; cols %d;" % [terminal.get_rows(), terminal.get_cols()])
|
||||
terminal.write("h")
|
||||
yield(get_tree().create_timer(1), "timeout")
|
||||
await get_tree().create_timer(1).timeout
|
||||
terminal.write(" i")
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
[ext_resource path="res://test/scenes/basic.gd" type="Script" id=3]
|
||||
|
||||
[node name="BasicNewTerm" type="Control"]
|
||||
margin_right = 43.0
|
||||
margin_bottom = 43.0
|
||||
offset_right = 43.0
|
||||
offset_bottom = 43.0
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
color = Color( 0, 1, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
|
|
@ -7,44 +7,44 @@ anchor_right = 1.0
|
|||
anchor_bottom = 1.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
offset_right = 1024.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextEdit" type="TextEdit" parent="HBoxContainer"]
|
||||
margin_right = 338.0
|
||||
margin_bottom = 600.0
|
||||
offset_right = 338.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
|
||||
margin_left = 342.0
|
||||
margin_right = 681.0
|
||||
margin_bottom = 600.0
|
||||
offset_left = 342.0
|
||||
offset_right = 681.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextEdit3" type="TextEdit" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_right = 339.0
|
||||
margin_bottom = 197.0
|
||||
offset_right = 339.0
|
||||
offset_bottom = 197.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Terminal" type="Control" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_top = 201.0
|
||||
margin_right = 339.0
|
||||
margin_bottom = 398.0
|
||||
offset_top = 201.0
|
||||
offset_right = 339.0
|
||||
offset_bottom = 398.0
|
||||
focus_mode = 2
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="TextEdit2" type="TextEdit" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_top = 402.0
|
||||
margin_right = 339.0
|
||||
margin_bottom = 600.0
|
||||
offset_top = 402.0
|
||||
offset_right = 339.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="TextEdit2" type="TextEdit" parent="HBoxContainer"]
|
||||
margin_left = 685.0
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
offset_left = 685.0
|
||||
offset_right = 1024.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[connection signal="data_sent" from="HBoxContainer/VBoxContainer/Terminal" to="HBoxContainer/VBoxContainer/Terminal" method="write"]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
tool
|
||||
@tool
|
||||
extends "res://addons/godot_xterm/terminal.gd"
|
||||
|
||||
signal theme_changed
|
||||
|
@ -27,7 +27,7 @@ func _ready():
|
|||
|
||||
|
||||
func _notification(what):
|
||||
._notification(what)
|
||||
super._notification(what)
|
||||
match what:
|
||||
NOTIFICATION_THEME_CHANGED:
|
||||
call_deferred("emit_signal", "theme_changed")
|
||||
|
|
|
@ -12,7 +12,7 @@ func _ready():
|
|||
|
||||
func _process(_delta):
|
||||
for _i in range(4096):
|
||||
write(PoolByteArray([rng.randi() % 256]))
|
||||
write(PackedByteArray([rng.randi() % 256]))
|
||||
"
|
||||
|
||||
[node name="Terminal" type="Control"]
|
||||
|
|
|
@ -21,18 +21,18 @@ class TestMultipleInputs:
|
|||
func press_key(scancode: int, unicode := 0) -> void:
|
||||
var key_down = InputEventKey.new()
|
||||
key_down.scancode = scancode
|
||||
key_down.pressed = true
|
||||
key_down.button_pressed = true
|
||||
Input.parse_input_event(key_down)
|
||||
yield(get_tree().create_timer(0.1), "timeout")
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
var key_up = InputEventKey.new()
|
||||
key_up.scancode = scancode
|
||||
key_up.pressed = false
|
||||
key_up.button_pressed = false
|
||||
Input.parse_input_event(key_up)
|
||||
|
||||
func before_each():
|
||||
var scene := preload("../scenes/multiple_inputs.tscn").instance()
|
||||
var scene := preload("../scenes/multiple_inputs.tscn").instantiate()
|
||||
add_child_autofree(scene)
|
||||
terminal = scene.find_node("Terminal")
|
||||
terminal = scene.find_child("Terminal")
|
||||
terminal.grab_focus()
|
||||
|
||||
func test_terminal_keeps_focus_when_certain_keys_pressed():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue