Update nn
drop termios dep
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user