From 01cf45dee4c4cc3941f18fef63978ba39a5b91fd Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 1 Sep 2020 15:14:01 +0200 Subject: [PATCH] Implement server that listens for connection from fake-editor script As well as a commit message editor! \o/ --- main.gd | 39 +++++++++++++++++++++++++++++++++++++++ main.tscn | 21 +++++++++++++++++++++ scripts/fake-editor | 2 +- terminal.gd | 7 ++++++- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/main.gd b/main.gd index 8061864..305d99e 100644 --- a/main.gd +++ b/main.gd @@ -8,10 +8,26 @@ var dragged = null var viewport_size +var server +var client_connection + func _ready(): viewport_size = get_viewport_rect().size + + server = TCP_Server.new() + server.listen(1234) +func _connected(id, proto): + print("!!!") + print(id) + +func _player_connected(id): + print("connected") + func _process(delta): + if server.is_connection_available(): + client_connection = server.take_connection() + read_commit_message() if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7: if Input.is_action_just_pressed("click"): var mindist = 9999999 @@ -30,6 +46,29 @@ func _process(delta): update_index() update_objects() apply_forces() + +func read_commit_message(): + $CommitMessage.show() + $Terminal/Input.editable = false + var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG" + var file = File.new() + file.open(file_path, File.READ) + var content = file.get_as_text() + file.close() + $CommitMessage.text = content + +func save_commit_message(): + var file = File.new() + var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG" + file.open(file_path, File.WRITE) + var content = $CommitMessage.text + file.store_string(content) + file.close() + print("disconnect") + client_connection.disconnect_from_host() + $Terminal/Input.editable = true + $CommitMessage.text = "" + $CommitMessage.hide() func update_index(): $Index.text = git("ls-files") diff --git a/main.tscn b/main.tscn index 3b1442e..f6aa6d0 100644 --- a/main.tscn +++ b/main.tscn @@ -49,4 +49,25 @@ margin_bottom = 1075.0 __meta__ = { "_edit_use_anchors_": false } + +[node name="CommitMessage" type="TextEdit" parent="."] +visible = false +margin_left = 889.832 +margin_top = 16.4234 +margin_right = 1388.83 +margin_bottom = 582.423 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Button" type="Button" parent="CommitMessage"] +margin_left = 344.277 +margin_top = 509.45 +margin_right = 493.277 +margin_bottom = 558.45 +text = "SAVE!" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"] +[connection signal="pressed" from="CommitMessage/Button" to="." method="save_commit_message"] diff --git a/scripts/fake-editor b/scripts/fake-editor index 37ef7e5..5f74036 100755 --- a/scripts/fake-editor +++ b/scripts/fake-editor @@ -2,5 +2,5 @@ echo Hi, I am commit-hook echo $* -zenity --question +nc localhost 1234 echo Goodbye diff --git a/terminal.gd b/terminal.gd index 3e9e9de..e96e12c 100644 --- a/terminal.gd +++ b/terminal.gd @@ -1,8 +1,13 @@ extends Node2D +var thread + func send_command(command): + thread = Thread.new() + thread.start(self, "run_command_in_a_thread", command) + +func run_command_in_a_thread(command): var cwd = run("pwd") - var output = [] var hacky_command = command