mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-03 20:14:22 +02: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
|
@ -17,9 +17,9 @@ const TITLE = """
|
|||
const TITLE_WIDTH = 42
|
||||
|
||||
var menu_items := [
|
||||
{ "name": "Asciicast", "scene": preload("../asciicast/asciicast.tscn") },
|
||||
{ "name": "Terminal", "scene": preload("../terminal/terminal.tscn") },
|
||||
{ "name": "Exit"}
|
||||
{"name": "Asciicast", "scene": preload("../asciicast/asciicast.tscn")},
|
||||
{"name": "Terminal", "scene": preload("../terminal/terminal.tscn")},
|
||||
{"name": "Exit"}
|
||||
]
|
||||
|
||||
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)))
|
||||
tput.reset()
|
||||
row = 5
|
||||
tput.civis() # Hide the cursor.
|
||||
tput.civis() # Hide the cursor.
|
||||
draw_title()
|
||||
draw_menu()
|
||||
tput.sgr0()
|
||||
|
@ -51,55 +51,54 @@ func draw_all(_size = Vector2.ZERO):
|
|||
|
||||
func draw_title():
|
||||
tput.cup(row, 0)
|
||||
|
||||
|
||||
for line in TITLE.split("\r"):
|
||||
row += 1
|
||||
tput.cup(row, offset)
|
||||
$Terminal.write(line)
|
||||
|
||||
|
||||
# Get the plugin version from the plugin's config file.
|
||||
var config = ConfigFile.new()
|
||||
var err = config.load("res://addons/godot_xterm/plugin.cfg")
|
||||
if err == OK:
|
||||
$Terminal.write("\n")
|
||||
$Terminal.write("Version: %s" % config.get_value("plugin", "version",
|
||||
"unknown"))
|
||||
$Terminal.write("Version: %s" % config.get_value("plugin", "version", "unknown"))
|
||||
row += 2
|
||||
|
||||
|
||||
func draw_menu():
|
||||
if not menu_start_row:
|
||||
menu_start_row = row + 1
|
||||
|
||||
|
||||
row = menu_start_row
|
||||
|
||||
|
||||
var col_offset: int
|
||||
|
||||
|
||||
for i in range(menu_items.size()):
|
||||
row += 1
|
||||
var item = menu_items[i]
|
||||
|
||||
|
||||
if not col_offset:
|
||||
col_offset = int(floor(($Terminal.cols / 2) - (item.name.length() / 2)))
|
||||
|
||||
|
||||
tput.cup(row, offset)
|
||||
|
||||
|
||||
if selected_index == i:
|
||||
tput.setab(Color("#FF7500"))
|
||||
tput.setaf(Color.black)
|
||||
|
||||
|
||||
$Terminal.write("%s. %s" % [i + 1, item.name])
|
||||
|
||||
|
||||
if selected_index == i:
|
||||
tput.sgr0()
|
||||
|
||||
|
||||
func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
||||
match(data):
|
||||
TPut.CURSOR_UP: # Up arrow key
|
||||
match data:
|
||||
TPut.CURSOR_UP: # Up arrow key
|
||||
selected_index = int(clamp(selected_index - 1, 0, menu_items.size() - 1))
|
||||
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))
|
||||
draw_menu()
|
||||
"1":
|
||||
|
@ -111,17 +110,16 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
|||
"3":
|
||||
selected_index = 2
|
||||
draw_menu()
|
||||
|
||||
|
||||
# We can also match against the raw InputEventKey.
|
||||
if event.scancode == KEY_ENTER:
|
||||
var item = menu_items[selected_index]
|
||||
|
||||
|
||||
match item.name:
|
||||
"Asciicast":
|
||||
var scene = item.scene.instance()
|
||||
var animation_player: AnimationPlayer = scene.get_node("AnimationPlayer")
|
||||
scene.connect("key_pressed", self, "_on_Asciicast_key_pressed",
|
||||
[animation_player])
|
||||
scene.connect("key_pressed", self, "_on_Asciicast_key_pressed", [animation_player])
|
||||
get_tree().get_root().add_child(scene)
|
||||
visible = false
|
||||
scene.grab_focus()
|
||||
|
@ -132,9 +130,15 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
|||
scene.queue_free()
|
||||
"Terminal":
|
||||
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"
|
||||
+ " to work on Windows.", "Terminal not Supported on Windows")
|
||||
+ " to work on Windows."
|
||||
),
|
||||
"Terminal not Supported on Windows"
|
||||
)
|
||||
var scene = item.scene.instance()
|
||||
var pty = scene.get_node("Pseudoterminal")
|
||||
get_tree().get_root().add_child(scene)
|
||||
|
@ -148,7 +152,8 @@ func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void:
|
|||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_Asciicast_key_pressed(data: String, _event: InputEventKey,
|
||||
animation_player: AnimationPlayer) -> void:
|
||||
func _on_Asciicast_key_pressed(
|
||||
data: String, _event: InputEventKey, animation_player: AnimationPlayer
|
||||
) -> void:
|
||||
if data == "\u001b":
|
||||
animation_player.emit_signal("animation_finished")
|
||||
|
|
|
@ -25,4 +25,5 @@ __meta__ = {
|
|||
}
|
||||
rows = 31
|
||||
cols = 102
|
||||
|
||||
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue