diff --git a/summarize_yt/cli.py b/summarize_yt/cli.py index 3c1aed9..1f4163d 100644 --- a/summarize_yt/cli.py +++ b/summarize_yt/cli.py @@ -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)