Close terminal on successful exit

This commit is contained in:
Leroy Hopson 2021-07-15 19:33:59 +07:00
parent ec0d4ddf43
commit 7c6300c8dc
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
3 changed files with 18 additions and 0 deletions

View file

@ -1,6 +1,8 @@
tool tool
extends "res://addons/godot_xterm/nodes/terminal/terminal.gd" extends "res://addons/godot_xterm/nodes/terminal/terminal.gd"
signal exited(exit_code, signum)
var editor_settings: EditorSettings var editor_settings: EditorSettings
var timer := Timer.new() var timer := Timer.new()
@ -83,3 +85,8 @@ func _input(event):
if event is InputEventKey: if event is InputEventKey:
get_tree().set_input_as_handled() get_tree().set_input_as_handled()
_gui_input(event) _gui_input(event)
func _on_PTY_exited(exit_code: int, signum: int):
print("exit_code: ", exit_code, " signum: ", signum)
emit_signal("exited", exit_code, signum)

View file

@ -23,3 +23,5 @@ env = {
"COLORTERM": "truecolor", "COLORTERM": "truecolor",
"TERM": "xterm-256color" "TERM": "xterm-256color"
} }
[connection signal="exited" from="PTY" to="." method="_on_PTY_exited"]

View file

@ -8,6 +8,7 @@ tool
extends Control extends Control
const EditorTerminal := preload("./editor_terminal.tscn") const EditorTerminal := preload("./editor_terminal.tscn")
const PTY := preload("../../nodes/pty/pty.gd")
const TerminalSettings := preload("./settings/terminal_settings.gd") const TerminalSettings := preload("./settings/terminal_settings.gd")
const SETTINGS_FILE_PATH := "res://.gdxterm/settings.tres" const SETTINGS_FILE_PATH := "res://.gdxterm/settings.tres"
@ -128,6 +129,7 @@ func _on_AddButton_pressed():
terminal.editor_settings = editor_settings terminal.editor_settings = editor_settings
terminal.set_anchors_preset(PRESET_WIDE) terminal.set_anchors_preset(PRESET_WIDE)
terminal.connect("gui_input", self, "_on_TabContainer_gui_input") terminal.connect("gui_input", self, "_on_TabContainer_gui_input")
terminal.connect("exited", self, "_on_Terminal_exited", [terminal])
tab_container.add_child(terminal) tab_container.add_child(terminal)
terminal.pty.fork(shell) terminal.pty.fork(shell)
terminal.grab_focus() terminal.grab_focus()
@ -269,3 +271,10 @@ func _on_Panel_resized():
func _on_SizeLabelTimer_timeout(): func _on_SizeLabelTimer_timeout():
if size_label: if size_label:
size_label.visible = false size_label.visible = false
func _on_Terminal_exited(exit_code, signum, terminal):
# Leave non-zero exit code terminals open in case they have some important
# error information.
if exit_code == 0:
_on_Tabs_tab_close(terminal.get_index())