refactor: Simplify user input logic using input() instead of low-level terminal handling
This commit is contained in:
@@ -240,39 +240,12 @@ def main():
|
||||
|
||||
if not args.yes:
|
||||
try:
|
||||
# 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())
|
||||
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()
|
||||
char = input().strip()
|
||||
|
||||
if not char or char.lower() != "y":
|
||||
response = input("\nDo you want to proceed with getting the summary? (y/N): ").strip().lower()
|
||||
if response != 'y':
|
||||
print("Operation cancelled by user.")
|
||||
cleanup_files(vtt_path)
|
||||
sys.exit(0)
|
||||
|
||||
except (EOFError, KeyboardInterrupt, termios.error):
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print("\nOperation cancelled by user.")
|
||||
cleanup_files(vtt_path)
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user