mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-25 02:30:27 +01:00
Format files using GDScript Toolkit
https://github.com/Scony/godot-gdscript-toolkit
This commit is contained in:
parent
a0237bb5d5
commit
f43149f204
10 changed files with 64 additions and 64 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Godot-specific ignores
|
# Godot-specific ignores
|
||||||
.import/
|
.import/
|
||||||
export.cfg
|
export.cfg
|
||||||
|
@ -7,3 +6,6 @@ export_presets.cfg
|
||||||
# Mono-specific ignores
|
# Mono-specific ignores
|
||||||
.mono/
|
.mono/
|
||||||
data_*/
|
data_*/
|
||||||
|
|
||||||
|
# Python-specific ignores
|
||||||
|
.venv
|
||||||
|
|
|
@ -37,40 +37,34 @@ func import(source_file, save_path, options, r_platform_variant, r_gen_files):
|
||||||
var err = file.open(source_file, File.READ)
|
var err = file.open(source_file, File.READ)
|
||||||
if err != OK:
|
if err != OK:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
var header = file.get_line()
|
var header = file.get_line()
|
||||||
|
|
||||||
var asciicast = Asciicast.new()
|
var asciicast = Asciicast.new()
|
||||||
|
|
||||||
asciicast.add_track(Animation.TYPE_METHOD, 0)
|
asciicast.add_track(Animation.TYPE_METHOD, 0)
|
||||||
asciicast.track_set_path(0, ".")
|
asciicast.track_set_path(0, ".")
|
||||||
|
|
||||||
var frame = {
|
var frame = {"time": 0.0, "data": {"method": "write", "args": [PoolByteArray()]}}
|
||||||
"time": 0.0,
|
|
||||||
"data": {
|
|
||||||
"method": "write",
|
|
||||||
"args": [PoolByteArray()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while not file.eof_reached():
|
while not file.eof_reached():
|
||||||
var line = file.get_line()
|
var line = file.get_line()
|
||||||
if line == "":
|
if line == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
var p = JSON.parse(line)
|
var p = JSON.parse(line)
|
||||||
if typeof(p.result) != TYPE_ARRAY:
|
if typeof(p.result) != TYPE_ARRAY:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
var event_type: String = p.result[1]
|
var event_type: String = p.result[1]
|
||||||
var event_data: PoolByteArray = p.result[2].to_utf8()
|
var event_data: PoolByteArray = p.result[2].to_utf8()
|
||||||
|
|
||||||
# Asciicast recordings have a resolution of 0.000001, however animation
|
# Asciicast recordings have a resolution of 0.000001, however animation
|
||||||
# track keys only have a resolution of 0.01, therefore we must combine
|
# track keys only have a resolution of 0.01, therefore we must combine
|
||||||
# events that would occur in the same keyframe, otherwise only the last
|
# events that would occur in the same keyframe, otherwise only the last
|
||||||
# event is inserted and the previous events are overwritten.
|
# event is inserted and the previous events are overwritten.
|
||||||
var time = stepify(p.result[0], 0.01)
|
var time = stepify(p.result[0], 0.01)
|
||||||
|
|
||||||
if event_type == "o":
|
if event_type == "o":
|
||||||
if time == frame.time:
|
if time == frame.time:
|
||||||
asciicast.track_remove_key_at_position(0, time)
|
asciicast.track_remove_key_at_position(0, time)
|
||||||
|
@ -78,9 +72,9 @@ func import(source_file, save_path, options, r_platform_variant, r_gen_files):
|
||||||
else:
|
else:
|
||||||
frame.time = time
|
frame.time = time
|
||||||
frame.data.args = [event_data]
|
frame.data.args = [event_data]
|
||||||
|
|
||||||
asciicast.track_insert_key(0, frame.time, frame.data)
|
asciicast.track_insert_key(0, frame.time, frame.data)
|
||||||
|
|
||||||
asciicast.length = frame.time
|
asciicast.length = frame.time
|
||||||
|
|
||||||
return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], asciicast)
|
return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], asciicast)
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
tool
|
tool
|
||||||
extends EditorPlugin
|
extends EditorPlugin
|
||||||
|
|
||||||
|
|
||||||
var asciicast_import_plugin
|
var asciicast_import_plugin
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
asciicast_import_plugin = preload("res://addons/godot_xterm/import_plugins/asciicast_import_plugin.gd").new()
|
asciicast_import_plugin = preload("res://addons/godot_xterm/import_plugins/asciicast_import_plugin.gd").new()
|
||||||
add_import_plugin(asciicast_import_plugin)
|
add_import_plugin(asciicast_import_plugin)
|
||||||
|
|
||||||
var asciicast_script = preload("res://addons/godot_xterm/resources/asciicast.gd")
|
var asciicast_script = preload("res://addons/godot_xterm/resources/asciicast.gd")
|
||||||
add_custom_type("Asciicast", "Animation", asciicast_script, null)
|
add_custom_type("Asciicast", "Animation", asciicast_script, null)
|
||||||
|
|
||||||
var terminal_script = preload("res://addons/godot_xterm/nodes/terminal/terminal.gdns")
|
var terminal_script = preload("res://addons/godot_xterm/nodes/terminal/terminal.gdns")
|
||||||
var terminal_icon = preload("res://addons/godot_xterm/nodes/terminal/terminal_icon.svg")
|
var terminal_icon = preload("res://addons/godot_xterm/nodes/terminal/terminal_icon.svg")
|
||||||
add_custom_type("Terminal", "Control", terminal_script, terminal_icon)
|
add_custom_type("Terminal", "Control", terminal_script, terminal_icon)
|
||||||
|
|
||||||
var pseudoterminal_script = preload("res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal.gdns")
|
var pseudoterminal_script = preload("res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal.gdns")
|
||||||
var pseudoterminal_icon = preload("res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal_icon.svg")
|
var pseudoterminal_icon = preload("res://addons/godot_xterm/nodes/pseudoterminal/pseudoterminal_icon.svg")
|
||||||
add_custom_type("Pseudoterminal", "Node", pseudoterminal_script, pseudoterminal_icon)
|
add_custom_type("Pseudoterminal", "Node", pseudoterminal_script, pseudoterminal_icon)
|
||||||
|
@ -24,7 +23,7 @@ func _enter_tree():
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
remove_import_plugin(asciicast_import_plugin)
|
remove_import_plugin(asciicast_import_plugin)
|
||||||
asciicast_import_plugin = null
|
asciicast_import_plugin = null
|
||||||
|
|
||||||
remove_custom_type("Asciicast")
|
remove_custom_type("Asciicast")
|
||||||
remove_custom_type("Terminal")
|
remove_custom_type("Terminal")
|
||||||
remove_custom_type("Psuedoterminal")
|
remove_custom_type("Psuedoterminal")
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
extends Animation
|
extends Animation
|
||||||
|
|
||||||
|
|
||||||
signal data_written(data)
|
signal data_written(data)
|
||||||
signal data_read(data)
|
signal data_read(data)
|
||||||
|
|
||||||
export(int) var version: int = 2
|
export (int) var version: int = 2
|
||||||
# Initial terminal width (number of columns).
|
# Initial terminal width (number of columns).
|
||||||
export(int) var width: int
|
export (int) var width: int
|
||||||
# Initial terminal height (number of rows).
|
# Initial terminal height (number of rows).
|
||||||
export(int) var height: int
|
export (int) var height: int
|
||||||
|
|
||||||
|
|
||||||
func get_class() -> String:
|
func get_class() -> String:
|
||||||
|
@ -20,4 +19,4 @@ func is_class(name) -> bool:
|
||||||
|
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
step = 0.01 # Parent override.
|
step = 0.01 # Parent override.
|
||||||
|
|
Binary file not shown.
|
@ -11,7 +11,6 @@ const CURSOR_LEFT = "\u001b[D"
|
||||||
|
|
||||||
const DEFAULT_FOREGROUND_COLOR = "\u001b[0m"
|
const DEFAULT_FOREGROUND_COLOR = "\u001b[0m"
|
||||||
|
|
||||||
|
|
||||||
var terminal
|
var terminal
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,12 +23,13 @@ func write_string(string: String, color: Color = Color.white) -> void:
|
||||||
if color:
|
if color:
|
||||||
var fg = "\u001b[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8]
|
var fg = "\u001b[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8]
|
||||||
terminal.write(fg.to_utf8())
|
terminal.write(fg.to_utf8())
|
||||||
|
|
||||||
terminal.write(string.to_utf8())
|
terminal.write(string.to_utf8())
|
||||||
|
|
||||||
# Reset color back to default.
|
# Reset color back to default.
|
||||||
terminal.write("\u001b[0m".to_utf8())
|
terminal.write("\u001b[0m".to_utf8())
|
||||||
|
|
||||||
|
|
||||||
# tput_* functions based on the tput command.
|
# tput_* functions based on the tput command.
|
||||||
# See: https://man7.org/linux/man-pages/man1/tput.1.html for more info.
|
# See: https://man7.org/linux/man-pages/man1/tput.1.html for more info.
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ extends Container
|
||||||
|
|
||||||
const ESCAPE = 27
|
const ESCAPE = 27
|
||||||
const BACKSPACE = 8
|
const BACKSPACE = 8
|
||||||
const BEEP = 7
|
const BEEP = 7
|
||||||
const SPACE = 32
|
const SPACE = 32
|
||||||
const LEFT_BRACKET = 91
|
const LEFT_BRACKET = 91
|
||||||
const ENTER = 10
|
const ENTER = 10
|
||||||
|
@ -13,6 +13,7 @@ const BACKSPACE_ALT = 127
|
||||||
|
|
||||||
onready var viewport = get_viewport()
|
onready var viewport = get_viewport()
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
viewport.connect("size_changed", self, "_resize")
|
viewport.connect("size_changed", self, "_resize")
|
||||||
_resize()
|
_resize()
|
||||||
|
@ -24,9 +25,9 @@ func _input(event):
|
||||||
if event is InputEventKey and event.pressed:
|
if event is InputEventKey and event.pressed:
|
||||||
var data = PoolByteArray([])
|
var data = PoolByteArray([])
|
||||||
accept_event()
|
accept_event()
|
||||||
|
|
||||||
# TODO: Handle more of these.
|
# TODO: Handle more of these.
|
||||||
if (event.control and event.scancode == KEY_C):
|
if event.control and event.scancode == KEY_C:
|
||||||
data.append(3)
|
data.append(3)
|
||||||
elif event.unicode:
|
elif event.unicode:
|
||||||
data.append(event.unicode)
|
data.append(event.unicode)
|
||||||
|
|
|
@ -17,9 +17,9 @@ const TITLE = """
|
||||||
const TITLE_WIDTH = 42
|
const TITLE_WIDTH = 42
|
||||||
|
|
||||||
var menu_items := [
|
var menu_items := [
|
||||||
{ "name": "Asciicast", "scene": preload("../asciicast/asciicast.tscn") },
|
{"name": "Asciicast", "scene": preload("../asciicast/asciicast.tscn")},
|
||||||
{ "name": "Terminal", "scene": preload("../terminal/terminal.tscn") },
|
{"name": "Terminal", "scene": preload("../terminal/terminal.tscn")},
|
||||||
{ "name": "Exit"}
|
{"name": "Exit"}
|
||||||
]
|
]
|
||||||
|
|
||||||
var selected_index := 0
|
var selected_index := 0
|
||||||
|
@ -42,7 +42,7 @@ func draw_all(_size = Vector2.ZERO):
|
||||||
offset = int(floor(($Terminal.cols / 2.0) - (TITLE_WIDTH / 2.0)))
|
offset = int(floor(($Terminal.cols / 2.0) - (TITLE_WIDTH / 2.0)))
|
||||||
tput.reset()
|
tput.reset()
|
||||||
row = 5
|
row = 5
|
||||||
tput.civis() # Hide the cursor.
|
tput.civis() # Hide the cursor.
|
||||||
draw_title()
|
draw_title()
|
||||||
draw_menu()
|
draw_menu()
|
||||||
tput.sgr0()
|
tput.sgr0()
|
||||||
|
@ -51,55 +51,54 @@ func draw_all(_size = Vector2.ZERO):
|
||||||
|
|
||||||
func draw_title():
|
func draw_title():
|
||||||
tput.cup(row, 0)
|
tput.cup(row, 0)
|
||||||
|
|
||||||
for line in TITLE.split("\r"):
|
for line in TITLE.split("\r"):
|
||||||
row += 1
|
row += 1
|
||||||
tput.cup(row, offset)
|
tput.cup(row, offset)
|
||||||
$Terminal.write(line)
|
$Terminal.write(line)
|
||||||
|
|
||||||
# Get the plugin version from the plugin's config file.
|
# Get the plugin version from the plugin's config file.
|
||||||
var config = ConfigFile.new()
|
var config = ConfigFile.new()
|
||||||
var err = config.load("res://addons/godot_xterm/plugin.cfg")
|
var err = config.load("res://addons/godot_xterm/plugin.cfg")
|
||||||
if err == OK:
|
if err == OK:
|
||||||
$Terminal.write("\n")
|
$Terminal.write("\n")
|
||||||
$Terminal.write("Version: %s" % config.get_value("plugin", "version",
|
$Terminal.write("Version: %s" % config.get_value("plugin", "version", "unknown"))
|
||||||
"unknown"))
|
|
||||||
row += 2
|
row += 2
|
||||||
|
|
||||||
|
|
||||||
func draw_menu():
|
func draw_menu():
|
||||||
if not menu_start_row:
|
if not menu_start_row:
|
||||||
menu_start_row = row + 1
|
menu_start_row = row + 1
|
||||||
|
|
||||||
row = menu_start_row
|
row = menu_start_row
|
||||||
|
|
||||||
var col_offset: int
|
var col_offset: int
|
||||||
|
|
||||||
for i in range(menu_items.size()):
|
for i in range(menu_items.size()):
|
||||||
row += 1
|
row += 1
|
||||||
var item = menu_items[i]
|
var item = menu_items[i]
|
||||||
|
|
||||||
if not col_offset:
|
if not col_offset:
|
||||||
col_offset = int(floor(($Terminal.cols / 2) - (item.name.length() / 2)))
|
col_offset = int(floor(($Terminal.cols / 2) - (item.name.length() / 2)))
|
||||||
|
|
||||||
tput.cup(row, offset)
|
tput.cup(row, offset)
|
||||||
|
|
||||||
if selected_index == i:
|
if selected_index == i:
|
||||||
tput.setab(Color("#FF7500"))
|
tput.setab(Color("#FF7500"))
|
||||||
tput.setaf(Color.black)
|
tput.setaf(Color.black)
|
||||||
|
|
||||||
$Terminal.write("%s. %s" % [i + 1, item.name])
|
$Terminal.write("%s. %s" % [i + 1, item.name])
|
||||||
|
|
||||||
if selected_index == i:
|
if selected_index == i:
|
||||||
tput.sgr0()
|
tput.sgr0()
|
||||||
|
|
||||||
|
|
||||||
func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
||||||
match(data):
|
match data:
|
||||||
TPut.CURSOR_UP: # Up arrow key
|
TPut.CURSOR_UP: # Up arrow key
|
||||||
selected_index = int(clamp(selected_index - 1, 0, menu_items.size() - 1))
|
selected_index = int(clamp(selected_index - 1, 0, menu_items.size() - 1))
|
||||||
draw_menu()
|
draw_menu()
|
||||||
TPut.CURSOR_DOWN: # Down arrow key
|
TPut.CURSOR_DOWN: # Down arrow key
|
||||||
selected_index = int(clamp(selected_index + 1, 0, menu_items.size() - 1))
|
selected_index = int(clamp(selected_index + 1, 0, menu_items.size() - 1))
|
||||||
draw_menu()
|
draw_menu()
|
||||||
"1":
|
"1":
|
||||||
|
@ -111,17 +110,16 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
||||||
"3":
|
"3":
|
||||||
selected_index = 2
|
selected_index = 2
|
||||||
draw_menu()
|
draw_menu()
|
||||||
|
|
||||||
# We can also match against the raw InputEventKey.
|
# We can also match against the raw InputEventKey.
|
||||||
if event.scancode == KEY_ENTER:
|
if event.scancode == KEY_ENTER:
|
||||||
var item = menu_items[selected_index]
|
var item = menu_items[selected_index]
|
||||||
|
|
||||||
match item.name:
|
match item.name:
|
||||||
"Asciicast":
|
"Asciicast":
|
||||||
var scene = item.scene.instance()
|
var scene = item.scene.instance()
|
||||||
var animation_player: AnimationPlayer = scene.get_node("AnimationPlayer")
|
var animation_player: AnimationPlayer = scene.get_node("AnimationPlayer")
|
||||||
scene.connect("key_pressed", self, "_on_Asciicast_key_pressed",
|
scene.connect("key_pressed", self, "_on_Asciicast_key_pressed", [animation_player])
|
||||||
[animation_player])
|
|
||||||
get_tree().get_root().add_child(scene)
|
get_tree().get_root().add_child(scene)
|
||||||
visible = false
|
visible = false
|
||||||
scene.grab_focus()
|
scene.grab_focus()
|
||||||
|
@ -132,9 +130,15 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
||||||
scene.queue_free()
|
scene.queue_free()
|
||||||
"Terminal":
|
"Terminal":
|
||||||
if OS.get_name() == "Windows":
|
if OS.get_name() == "Windows":
|
||||||
return OS.call_deferred("alert", "Psuedoterminal node currently"
|
return OS.call_deferred(
|
||||||
|
"alert",
|
||||||
|
(
|
||||||
|
"Psuedoterminal node currently"
|
||||||
+ " uses pty.h but needs to use either winpty or conpty"
|
+ " uses pty.h but needs to use either winpty or conpty"
|
||||||
+ " to work on Windows.", "Terminal not Supported on Windows")
|
+ " to work on Windows."
|
||||||
|
),
|
||||||
|
"Terminal not Supported on Windows"
|
||||||
|
)
|
||||||
var scene = item.scene.instance()
|
var scene = item.scene.instance()
|
||||||
var pty = scene.get_node("Pseudoterminal")
|
var pty = scene.get_node("Pseudoterminal")
|
||||||
get_tree().get_root().add_child(scene)
|
get_tree().get_root().add_child(scene)
|
||||||
|
@ -148,7 +152,8 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
func _on_Asciicast_key_pressed(data: String, _event: InputEventKey,
|
func _on_Asciicast_key_pressed(
|
||||||
animation_player: AnimationPlayer) -> void:
|
data: String, _event: InputEventKey, animation_player: AnimationPlayer
|
||||||
|
) -> void:
|
||||||
if data == "\u001b":
|
if data == "\u001b":
|
||||||
animation_player.emit_signal("animation_finished")
|
animation_player.emit_signal("animation_finished")
|
||||||
|
|
|
@ -25,4 +25,5 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
rows = 31
|
rows = 31
|
||||||
cols = 102
|
cols = 102
|
||||||
|
|
||||||
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]
|
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_Terminal_key_pressed(event: InputEventKey, data: PoolByteArray):
|
func _on_Terminal_key_pressed(event: InputEventKey, data: PoolByteArray):
|
||||||
print(data as Array)
|
print(data as Array)
|
||||||
print(event.scancode)
|
print(event.scancode)
|
||||||
|
|
Loading…
Reference in a new issue