Skip to content

Commit f484e41

Browse files
authored
Implement control-t to toggle password visibility
The keybindings object must be passed to prompt, and the is_password argument must be a Condition (a/k/a filter). prompt('prompt: ', is_password=Condition(lambda: hidden[0]), key_bindings=key_bindings)
1 parent 26c230e commit f484e41

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

onlykey/cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ def cli():
2727

2828
logging.basicConfig(level=logging.DEBUG)
2929

30-
# ContrlT handling
30+
# Control-T handling
3131
hidden = [True] # Nonlocal
3232
key_bindings = KeyBindings()
3333

3434
@key_bindings.add('c-t')
3535
def _(event):
36-
' When ControlT has been pressed, toggle visibility. '
36+
' When Control-T has been pressed, toggle visibility. '
3737
hidden[0] = not hidden[0]
3838

3939
def prompt_pass():
4040
print('Type Control-T to toggle password visible.')
41-
password = prompt('Password/Key: ', is_password=True)
41+
password = prompt('Password/Key: ',
42+
is_password=Condition(lambda: hidden[0]),
43+
key_bindings=key_bindings)
4244
return password
4345

4446
def prompt_key():
4547
print('Type Control-T to toggle key visible.')
46-
key = prompt('Key: ', is_password=True)
48+
key = prompt('Key: ',
49+
is_password=Condition(lambda: hidden[0]),
50+
key_bindings=key_bindings)
4751
return key
4852

4953
def prompt_pin():

0 commit comments

Comments
 (0)