I am writing an interactive CLI and just thought about giving the user a different way of confirming an input.
So, usually I would use python’s input()
.
With that a user would submit input by pressing Enter
.
Would it be possible to let a user submit input by pressing e.g. Tab
or Ctrl+D
?
I tried around with Ctrl+D
(by catching EOFError
)
<code>def _input(msg: str) -> str:
try:
inpt = input(msg)
except EOFError:
pass
return inpt
</code>
<code>def _input(msg: str) -> str:
try:
inpt = input(msg)
except EOFError:
pass
return inpt
</code>
def _input(msg: str) -> str:
try:
inpt = input(msg)
except EOFError:
pass
return inpt
but of course that doesn’t work because the exception prevents user input from being read.