fix: Improve user input handling for y/N prompt in CLI
This commit is contained in:
@@ -246,27 +246,34 @@ def main():
|
|||||||
|
|
||||||
if not args.yes:
|
if not args.yes:
|
||||||
try:
|
try:
|
||||||
import tty
|
# Check if running in a terminal
|
||||||
import termios
|
if sys.stdin.isatty():
|
||||||
|
import tty
|
||||||
|
import termios
|
||||||
|
|
||||||
# Save the terminal settings
|
# Save the terminal settings
|
||||||
fd = sys.stdin.fileno()
|
fd = sys.stdin.fileno()
|
||||||
old_settings = termios.tcgetattr(fd)
|
old_settings = termios.tcgetattr(fd)
|
||||||
try:
|
try:
|
||||||
# Set the terminal to raw mode
|
# Set the terminal to raw mode
|
||||||
tty.setraw(sys.stdin.fileno())
|
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.write("\nDo you want to proceed with getting the summary? (y/N): ")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
# Read a single character
|
char = input().strip()
|
||||||
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)
|
|
||||||
|
|
||||||
if char.lower() != "y":
|
if not char or char.lower() != "y":
|
||||||
print("Operation cancelled by user.")
|
print("Operation cancelled by user.")
|
||||||
cleanup_files(vtt_path)
|
cleanup_files(vtt_path)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user