Move input handling into the Terminal node

Former-commit-id: d64800229f
This commit is contained in:
Leroy Hopson 2020-09-24 17:29:19 +07:00
parent 9d06d7c313
commit 5e33e560f1
6 changed files with 223 additions and 74 deletions

View file

@ -1,23 +1,22 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://addons/godot_xterm/nodes/terminal/terminal.gdns" type="Script" id=1]
[ext_resource path="res://addons/godot_xterm/themes/default.theme" type="Theme" id=2]
[ext_resource path="res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal.gdns" type="Script" id=3]
[ext_resource path="res://examples/terminal/container.gd" type="Script" id=4]
[ext_resource path="res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal.gdns" type="Script" id=2]
[ext_resource path="res://addons/godot_xterm/themes/default.theme" type="Theme" id=4]
[node name="Container" type="Container"]
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 4 )
[node name="Terminal" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
focus_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 4 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Terminal" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0
theme = ExtResource( 2 )
script = ExtResource( 1 )
[node name="Pseudoterminal" type="Node" parent="."]
script = ExtResource( 3 )
script = ExtResource( 2 )
[connection signal="data_read" from="." to="Pseudoterminal" method="put_data"]
[connection signal="data_received" from="Pseudoterminal" to="." method="write"]

View file

@ -1,55 +0,0 @@
extends Container
# This Container ensures that the terminal always fills
# the window and/or screen. It also connects the terminal
# to the input/output of the Psuedoterminal.
const ESCAPE = 27
const BACKSPACE = 8
const BEEP = 7
const SPACE = 32
const LEFT_BRACKET = 91
const ENTER = 10
const BACKSPACE_ALT = 127
onready var viewport = get_viewport()
func _ready():
$Pseudoterminal.connect("data_received", $Terminal, "write")
viewport.connect("size_changed", self, "_resize")
_resize()
func _input(event):
#return
if event is InputEventKey and event.pressed:
var data = PoolByteArray([])
accept_event()
# TODO: Handle more of these.
if (event.control and event.scancode == KEY_C):
data.append(3)
elif event.unicode:
data.append(event.unicode)
elif event.scancode == KEY_ENTER:
data.append(ENTER)
elif event.scancode == KEY_BACKSPACE:
data.append(BACKSPACE_ALT)
elif event.scancode == KEY_ESCAPE:
data.append(27)
elif event.scancode == KEY_TAB:
data.append(9)
elif OS.get_scancode_string(event.scancode) == "Shift":
pass
elif OS.get_scancode_string(event.scancode) == "Control":
pass
else:
pass
#push_warning('Unhandled input. scancode: ' + str(OS.get_scancode_string(event.scancode)))
#emit_signal("output", data)
$Pseudoterminal.put_data(data)
func _resize():
rect_size = viewport.size
$Terminal.rect_size = rect_size