Update nn

drop termios dep
This commit is contained in:
2026-08-28 14:43:24 +02:00
parent d2d8c7dbf6
commit f1d29d5109
+11 -19
View File
@@ -6,8 +6,6 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import termios
import tty
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
@@ -293,24 +291,18 @@ def apply_renames(plan):
return count return count
def confirm(prompt='Apply renames? [y/n] '): def confirm(prompt='Apply renames? [Y/n] '):
"""Ask the user for confirmation, reacting to a single keypress.""" """Ask the user for confirmation. An empty answer accepts the default (yes)."""
print(prompt, end='', flush=True) while True:
if not sys.stdin.isatty():
return sys.stdin.read(1).strip().lower() == 'y'
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try: try:
# cbreak (not raw) keeps Ctrl-C as SIGINT and newlines well behaved. answer = input(prompt).strip().lower()
tty.setcbreak(fd) except EOFError:
while (key := sys.stdin.read(1).lower()) not in ('y', 'n', ''): print()
pass return True
finally: if answer in ('', 'y', 'yes'):
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return True
if answer in ('n', 'no'):
print(key) return False
return key == 'y'
def main(): def main():