Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #142 from j00bar/password-input
Browse files Browse the repository at this point in the history
Support password inputs in textui.prompt.query
  • Loading branch information
kennethreitz committed Aug 29, 2017
2 parents 9601343 + a09b1ef commit 8f42b40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clint/textui/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import absolute_import, print_function

from re import match, I
import getpass

from .core import puts
from .colored import yellow
Expand Down Expand Up @@ -59,7 +60,7 @@ def yn(prompt, default='y', batch=False):
return True if default == 'n' else False


def query(prompt, default='', validators=None, batch=False):
def query(prompt, default='', validators=None, batch=False, mask_input=False):
# Set the nonempty validator as default
if validators is None:
validators = [RegexValidator(r'.+')]
Expand All @@ -76,7 +77,8 @@ def query(prompt, default='', validators=None, batch=False):
# If batch option is True then auto reply
# with default input
if not batch:
user_input = raw_input(prompt).strip() or default
user_input_fn = getpass.getpass if mask_input else raw_input
user_input = user_input_fn(prompt).strip() or default
else:
print(prompt)
user_input = ''
Expand Down

0 comments on commit 8f42b40

Please sign in to comment.