Using Confirm
without pressing Enter?
#3319
Unanswered
I-love-study
asked this question in
General
Replies: 2 comments
-
rich.prompt is not really advanced, i'd prefer questionary library which provides everything one needs about inputs. |
Beta Was this translation helpful? Give feedback.
0 replies
-
in my Linux I manage to do a fake conform (but it works): import curses
def get_confirmation(stdscr):
stdscr.clear()
stdscr.addstr("Do you want to continue? (Y/N) ")
stdscr.refresh()
while True:
key = stdscr.getch()
if key in [ord('y'), ord('Y')]:
return True
else:
return False
confirm = get_confirmation(curses.initscr()) Method 2: import sys
import tty
import termios
from rich.prompt import Confirm
def get_confirmation():
print("Are you sure? [y/n] ", end="")
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
if ch.lower() == "y":
# get the cursor into the right position.
return True
else:
return False
confirm = get_confirmation()
print(confirm) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In
Confirm
now, Only after press Enter, The program can continue to run.I think it would be better if
Confirm
could directly return the obtained characters when the key is pressed. And here is how python returns it directly after getting a single character on some platforms(without 3rd party lib).I think it would be great if Confirm could add a
pressing_enter
parameter to let user can choose it.Beta Was this translation helpful? Give feedback.
All reactions