test
This commit is contained in:
parent
92cce93edd
commit
257022ba6d
1 changed files with 34 additions and 17 deletions
|
|
@ -11,6 +11,7 @@ import tempfile
|
||||||
import psutil
|
import psutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import getpass
|
import getpass
|
||||||
|
import shutil
|
||||||
|
|
||||||
if (os.name != "nt"):
|
if (os.name != "nt"):
|
||||||
import pty
|
import pty
|
||||||
|
|
@ -713,28 +714,44 @@ def main():
|
||||||
pygame.mixer.quit()
|
pygame.mixer.quit()
|
||||||
|
|
||||||
def has_terminal():
|
def has_terminal():
|
||||||
|
"""Check if stdout and stdin are attached to a terminal."""
|
||||||
|
try:
|
||||||
return sys.stdout.isatty() and sys.stdin.isatty()
|
return sys.stdout.isatty() and sys.stdin.isatty()
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
def relaunch_in_terminal():
|
def relaunch_in_terminal():
|
||||||
# Detect the current folder and script/binary path
|
"""Relaunch this program inside a terminal emulator."""
|
||||||
script = os.path.abspath(sys.argv[0])
|
# 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 = [
|
terminals = [
|
||||||
["konsole", "--hold", "-e"],
|
["konsole", "--hold", "-e"], # KDE
|
||||||
["gnome-terminal", "--", "bash", "-c"],
|
["gnome-terminal", "--", "bash", "-c"], # GNOME
|
||||||
["xterm", "-hold", "-e"]
|
["xterm", "-hold", "-e"], # X11 fallback
|
||||||
|
["kitty", "-e"], # Kitty
|
||||||
|
["alacritty", "-e"] # Alacritty
|
||||||
]
|
]
|
||||||
|
|
||||||
for term in terminals:
|
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:
|
try:
|
||||||
subprocess.Popen(term + [script] + sys.argv[1:])
|
subprocess.Popen(cmd)
|
||||||
sys.exit(0) # exit the current GUI-launched process
|
sys.exit(0)
|
||||||
except FileNotFoundError:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If no terminal found, just print a warning
|
# If no terminal found, print a warning and exit
|
||||||
print("No terminal emulator found. Please run from a terminal.")
|
print("No terminal emulator found. Please run this program from a terminal.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if (os.name != "nt"):
|
if (os.name != "nt"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue