Update nn
drop termios dep
This commit is contained in:
@@ -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():
|
try:
|
||||||
return sys.stdin.read(1).strip().lower() == 'y'
|
answer = input(prompt).strip().lower()
|
||||||
|
except EOFError:
|
||||||
fd = sys.stdin.fileno()
|
print()
|
||||||
old_settings = termios.tcgetattr(fd)
|
return True
|
||||||
try:
|
if answer in ('', 'y', 'yes'):
|
||||||
# cbreak (not raw) keeps Ctrl-C as SIGINT and newlines well behaved.
|
return True
|
||||||
tty.setcbreak(fd)
|
if answer in ('n', 'no'):
|
||||||
while (key := sys.stdin.read(1).lower()) not in ('y', 'n', ''):
|
return False
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
|
||||||
|
|
||||||
print(key)
|
|
||||||
return key == 'y'
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user