2020-09-01 21:25:24 +02:00
|
|
|
extends Control
|
2020-06-10 18:25:41 +02:00
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
var thread
|
|
|
|
|
2020-09-01 19:59:07 +02:00
|
|
|
var history = []
|
|
|
|
var history_position = 0
|
|
|
|
|
2020-09-14 19:36:58 +02:00
|
|
|
onready var input = $Control/InputLine/Input
|
2020-09-01 21:25:24 +02:00
|
|
|
onready var output = $Control/Output
|
2020-09-21 15:25:54 +02:00
|
|
|
export(NodePath) var repository_path
|
|
|
|
onready var repository = get_node(repository_path)
|
2020-09-14 19:36:58 +02:00
|
|
|
onready var command_dropdown = $Control/InputLine/CommandDropdown
|
2020-09-21 15:25:54 +02:00
|
|
|
onready var main = get_tree().get_root().get_node("Main")
|
2020-09-01 21:25:24 +02:00
|
|
|
|
2020-09-14 19:25:57 +02:00
|
|
|
var premade_commands = [
|
|
|
|
'git commit --allow-empty -m "empty"',
|
|
|
|
'echo $RANDOM | git hash-object -w --stdin',
|
|
|
|
'git switch -c $RANDOM',
|
|
|
|
]
|
|
|
|
|
2020-09-08 22:16:18 +02:00
|
|
|
func _ready():
|
2020-09-21 15:25:54 +02:00
|
|
|
#repository.shell.connect("output", self, "receive_output")
|
2020-09-08 22:16:18 +02:00
|
|
|
|
2020-09-14 19:25:57 +02:00
|
|
|
for command in premade_commands:
|
|
|
|
command_dropdown.get_popup().add_item(command)
|
|
|
|
command_dropdown.get_popup().connect("id_pressed", self, "load_command")
|
2020-09-21 18:59:55 +02:00
|
|
|
|
|
|
|
$TextEditor.connect("hide", self, "editor_closed")
|
2020-09-22 21:56:22 +02:00
|
|
|
input.grab_focus()
|
2020-09-14 19:25:57 +02:00
|
|
|
|
2020-09-21 20:28:43 +02:00
|
|
|
func _input(event):
|
|
|
|
if history.size() > 0:
|
|
|
|
if event.is_action_pressed("ui_up"):
|
|
|
|
if history_position > 0:
|
|
|
|
history_position -= 1
|
|
|
|
input.text = history[history_position]
|
|
|
|
input.caret_position = input.text.length()
|
|
|
|
# This prevents the Input taking the arrow as a "skip to beginning" command.
|
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
if event.is_action_pressed("ui_down"):
|
|
|
|
if history_position < history.size()-1:
|
|
|
|
history_position += 1
|
|
|
|
input.text = history[history_position]
|
|
|
|
input.caret_position = input.text.length()
|
|
|
|
get_tree().set_input_as_handled()
|
2020-09-01 19:59:07 +02:00
|
|
|
|
2020-09-14 19:25:57 +02:00
|
|
|
func load_command(id):
|
|
|
|
input.text = premade_commands[id]
|
|
|
|
input.caret_position = input.text.length()
|
|
|
|
|
2020-09-01 14:03:18 +02:00
|
|
|
func send_command(command):
|
2020-09-01 19:59:07 +02:00
|
|
|
history.push_back(command)
|
2020-09-05 10:47:38 +02:00
|
|
|
history_position = history.size()
|
2020-09-01 19:59:07 +02:00
|
|
|
|
2020-09-11 10:33:44 +02:00
|
|
|
input.editable = false
|
|
|
|
|
|
|
|
if thread != null:
|
|
|
|
thread.wait_to_finish()
|
2020-09-01 15:14:01 +02:00
|
|
|
thread = Thread.new()
|
|
|
|
thread.start(self, "run_command_in_a_thread", command)
|
|
|
|
|
2020-09-08 22:16:18 +02:00
|
|
|
func send_command_async(command):
|
2020-09-24 10:10:14 +02:00
|
|
|
#output.text += "$ "+command+"\n"
|
2020-09-08 22:16:18 +02:00
|
|
|
input.text = ""
|
2020-09-24 10:10:14 +02:00
|
|
|
#repository.shell.run_async(command)
|
|
|
|
$TCPServer.send(command+"\n")
|
2020-09-08 22:16:18 +02:00
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
func run_command_in_a_thread(command):
|
2020-09-21 15:25:54 +02:00
|
|
|
var o = repository.shell.run(command)
|
2020-09-10 12:03:46 +02:00
|
|
|
check_win_condition()
|
2020-09-01 14:03:18 +02:00
|
|
|
|
2020-09-01 21:25:24 +02:00
|
|
|
input.text = ""
|
2020-09-11 12:23:26 +02:00
|
|
|
input.editable = true
|
2020-09-01 21:25:24 +02:00
|
|
|
output.text = output.text + "$ " + command + "\n" + o
|
2020-09-21 15:25:54 +02:00
|
|
|
repository.update_everything()
|
2020-09-08 22:16:18 +02:00
|
|
|
|
|
|
|
func receive_output(text):
|
|
|
|
output.text += text
|
2020-09-24 10:10:14 +02:00
|
|
|
repository.update_everything()
|
2020-09-14 15:35:30 +02:00
|
|
|
|
|
|
|
func clear():
|
|
|
|
output.text = ""
|
2020-09-10 12:03:46 +02:00
|
|
|
|
2020-09-21 18:59:55 +02:00
|
|
|
func editor_closed():
|
|
|
|
input.grab_focus()
|
|
|
|
|
2020-09-10 12:03:46 +02:00
|
|
|
func check_win_condition():
|
2020-09-21 15:25:54 +02:00
|
|
|
if repository.shell.run("bash /tmp/win 2>/dev/null >/dev/null && echo yes || echo no") == "yes\n":
|
2020-09-11 13:12:12 +02:00
|
|
|
main.show_win_status()
|