This commit is contained in:
edschuy95 2026-01-22 01:49:32 -05:00
parent 92cce93edd
commit 257022ba6d

View file

@ -11,6 +11,7 @@ import tempfile
import psutil
import subprocess
import getpass
import shutil
if (os.name != "nt"):
import pty
@ -713,28 +714,44 @@ def main():
pygame.mixer.quit()
def has_terminal():
"""Check if stdout and stdin are attached to a terminal."""
try:
return sys.stdout.isatty() and sys.stdin.isatty()
except Exception:
return False
def relaunch_in_terminal():
# Detect the current folder and script/binary path
script = os.path.abspath(sys.argv[0])
"""Relaunch this program inside a terminal emulator."""
# Full path to the current script or binary
script_path = os.path.abspath(sys.argv[0])
args = sys.argv[1:]
# Choose a terminal emulator (Konsole, GNOME Terminal, xterm)
# Common terminal emulators to try
terminals = [
["konsole", "--hold", "-e"],
["gnome-terminal", "--", "bash", "-c"],
["xterm", "-hold", "-e"]
["konsole", "--hold", "-e"], # KDE
["gnome-terminal", "--", "bash", "-c"], # GNOME
["xterm", "-hold", "-e"], # X11 fallback
["kitty", "-e"], # Kitty
["alacritty", "-e"] # Alacritty
]
for term in terminals:
# Check if terminal exists
if shutil.which(term[0]):
# For GNOME Terminal, wrap command in bash -c
if "gnome-terminal" in term[0]:
cmd = term + [f'"{script_path}" {" ".join(args)}; exec bash"']
else:
cmd = term + [script_path] + args
try:
subprocess.Popen(term + [script] + sys.argv[1:])
sys.exit(0) # exit the current GUI-launched process
except FileNotFoundError:
subprocess.Popen(cmd)
sys.exit(0)
except Exception:
continue
# If no terminal found, just print a warning
print("No terminal emulator found. Please run from a terminal.")
# If no terminal found, print a warning and exit
print("No terminal emulator found. Please run this program from a terminal.")
sys.exit(1)
if __name__ == "__main__":
if (os.name != "nt"):