diff --git a/bin/nn b/bin/nn index 1c4b140..ce41202 100755 --- a/bin/nn +++ b/bin/nn @@ -6,8 +6,6 @@ import re import shutil import subprocess import sys -import termios -import tty from datetime import datetime from pathlib import Path @@ -293,24 +291,18 @@ def apply_renames(plan): return count -def confirm(prompt='Apply renames? [y/n] '): - """Ask the user for confirmation, reacting to a single keypress.""" - print(prompt, end='', flush=True) - if not sys.stdin.isatty(): - return sys.stdin.read(1).strip().lower() == 'y' - - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - # cbreak (not raw) keeps Ctrl-C as SIGINT and newlines well behaved. - tty.setcbreak(fd) - while (key := sys.stdin.read(1).lower()) not in ('y', 'n', ''): - pass - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - - print(key) - return key == 'y' +def confirm(prompt='Apply renames? [Y/n] '): + """Ask the user for confirmation. An empty answer accepts the default (yes).""" + while True: + try: + answer = input(prompt).strip().lower() + except EOFError: + print() + return True + if answer in ('', 'y', 'yes'): + return True + if answer in ('n', 'no'): + return False def main():