fix: Improve user input handling for y/N prompt in CLI

This commit is contained in:
2025-01-03 13:47:57 +01:00
parent 3cbb749655
commit d4f96d72d8

View File

@@ -246,27 +246,34 @@ def main():
if not args.yes:
try:
import tty
import termios
# Check if running in a terminal
if sys.stdin.isatty():
import tty
import termios
# Save the terminal settings
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
# Set the terminal to raw mode
tty.setraw(sys.stdin.fileno())
# Save the terminal settings
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
# Set the terminal to raw mode
tty.setraw(sys.stdin.fileno())
sys.stdout.write("\nDo you want to proceed with getting the summary? (y/N): ")
sys.stdout.flush()
# Read a single character
char = sys.stdin.read(1)
# Print a newline since we're in raw mode
sys.stdout.write("\n")
sys.stdout.flush()
finally:
# Restore terminal settings
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
else:
# If not in a terminal, use regular input
sys.stdout.write("\nDo you want to proceed with getting the summary? (y/N): ")
sys.stdout.flush()
# Read a single character
char = sys.stdin.read(1)
# Print a newline since we're in raw mode
sys.stdout.write("\n")
sys.stdout.flush()
finally:
# Restore terminal settings
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
char = input().strip()
if char.lower() != "y":
if not char or char.lower() != "y":
print("Operation cancelled by user.")
cleanup_files(vtt_path)
sys.exit(0)