-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor_terminal.py
More file actions
37 lines (32 loc) · 1.14 KB
/
executor_terminal.py
File metadata and controls
37 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Moduł obsługi terminala - resetowanie stanu terminala po komendach.
"""
import sys
import subprocess
try:
import termios
import tty
UNIX_AVAILABLE = True
except ImportError:
UNIX_AVAILABLE = False # Windows
def reset_terminal_state():
"""Resetuje stan terminala dla uniknięcia blokowania na Linux."""
if not UNIX_AVAILABLE:
return # Windows nie potrzebuje resetu terminala
try:
# Przywróć ustawienia terminala
if hasattr(sys.stdin, 'fileno'):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
# Dodatkowo wymuś tryb kanoniczny
new_settings = termios.tcgetattr(fd)
new_settings[3] = new_settings[3] | termios.ICANON | termios.ECHO
termios.tcsetattr(fd, termios.TCSADRAIN, new_settings)
except:
pass # Ignoruj błędy na macOS/Windows
# Ostateczność - uruchom stty sane (tylko Unix)
try:
subprocess.run(['stty', 'sane'], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, timeout=1)
except:
pass