@@ -249,6 +249,7 @@ class PromptSession(Generic[_T]):
249
249
When True (the default), automatically wrap long lines instead of
250
250
scrolling horizontally.
251
251
:param is_password: Show asterisks instead of the actual typed characters.
252
+ :param hide_password: Hide the password, rather than showing asterisks.
252
253
:param editing_mode: ``EditingMode.VI`` or ``EditingMode.EMACS``.
253
254
:param vi_mode: `bool`, if True, Identical to ``editing_mode=EditingMode.VI``.
254
255
:param complete_while_typing: `bool` or
@@ -335,10 +336,10 @@ class PromptSession(Generic[_T]):
335
336
"lexer" ,
336
337
"completer" ,
337
338
"complete_in_thread" ,
338
- "is_password" ,
339
339
"editing_mode" ,
340
340
"key_bindings" ,
341
341
"is_password" ,
342
+ "hide_password" ,
342
343
"bottom_toolbar" ,
343
344
"style" ,
344
345
"style_transformation" ,
@@ -377,6 +378,7 @@ def __init__(
377
378
multiline : FilterOrBool = False ,
378
379
wrap_lines : FilterOrBool = True ,
379
380
is_password : FilterOrBool = False ,
381
+ hide_password : bool = False ,
380
382
vi_mode : bool = False ,
381
383
editing_mode : EditingMode = EditingMode .EMACS ,
382
384
complete_while_typing : FilterOrBool = True ,
@@ -435,6 +437,7 @@ def __init__(
435
437
self .completer = completer
436
438
self .complete_in_thread = complete_in_thread
437
439
self .is_password = is_password
440
+ self .hide_password = hide_password
438
441
self .key_bindings = key_bindings
439
442
self .bottom_toolbar = bottom_toolbar
440
443
self .style = style
@@ -555,13 +558,17 @@ def _create_layout(self) -> Layout:
555
558
def display_placeholder () -> bool :
556
559
return self .placeholder is not None and self .default_buffer .text == ""
557
560
561
+ password_character = "" if self .hide_password else "*"
562
+
558
563
all_input_processors = [
559
564
HighlightIncrementalSearchProcessor (),
560
565
HighlightSelectionProcessor (),
561
566
ConditionalProcessor (
562
567
AppendAutoSuggestion (), has_focus (default_buffer ) & ~ is_done
563
568
),
564
- ConditionalProcessor (PasswordProcessor (), dyncond ("is_password" )),
569
+ ConditionalProcessor (
570
+ PasswordProcessor (char = password_character ), dyncond ("is_password" )
571
+ ),
565
572
DisplayMultipleCursors (),
566
573
# Users can insert processors here.
567
574
DynamicProcessor (lambda : merge_processors (self .input_processors or [])),
@@ -866,6 +873,7 @@ def prompt(
866
873
completer : Completer | None = None ,
867
874
complete_in_thread : bool | None = None ,
868
875
is_password : bool | None = None ,
876
+ hide_password : bool | None = None ,
869
877
key_bindings : KeyBindingsBase | None = None ,
870
878
bottom_toolbar : AnyFormattedText | None = None ,
871
879
style : BaseStyle | None = None ,
@@ -961,6 +969,8 @@ class itself. For these, passing in ``None`` will keep the current
961
969
self .complete_in_thread = complete_in_thread
962
970
if is_password is not None :
963
971
self .is_password = is_password
972
+ if hide_password is not None :
973
+ self .hide_password = hide_password
964
974
if key_bindings is not None :
965
975
self .key_bindings = key_bindings
966
976
if bottom_toolbar is not None :
@@ -1103,6 +1113,7 @@ async def prompt_async(
1103
1113
completer : Completer | None = None ,
1104
1114
complete_in_thread : bool | None = None ,
1105
1115
is_password : bool | None = None ,
1116
+ hide_password : bool | None = None ,
1106
1117
key_bindings : KeyBindingsBase | None = None ,
1107
1118
bottom_toolbar : AnyFormattedText | None = None ,
1108
1119
style : BaseStyle | None = None ,
@@ -1155,6 +1166,8 @@ async def prompt_async(
1155
1166
self .complete_in_thread = complete_in_thread
1156
1167
if is_password is not None :
1157
1168
self .is_password = is_password
1169
+ if hide_password is not None :
1170
+ self .hide_password = hide_password
1158
1171
if key_bindings is not None :
1159
1172
self .key_bindings = key_bindings
1160
1173
if bottom_toolbar is not None :
@@ -1376,6 +1389,7 @@ def prompt(
1376
1389
completer : Completer | None = None ,
1377
1390
complete_in_thread : bool | None = None ,
1378
1391
is_password : bool | None = None ,
1392
+ hide_password : bool | None = None ,
1379
1393
key_bindings : KeyBindingsBase | None = None ,
1380
1394
bottom_toolbar : AnyFormattedText | None = None ,
1381
1395
style : BaseStyle | None = None ,
@@ -1420,7 +1434,9 @@ def prompt(
1420
1434
"""
1421
1435
# The history is the only attribute that has to be passed to the
1422
1436
# `PromptSession`, it can't be passed into the `prompt()` method.
1423
- session : PromptSession [str ] = PromptSession (history = history )
1437
+ # The `hide_password` is needed by the layout, so must be provided
1438
+ # in the init as well.
1439
+ session : PromptSession [str ] = PromptSession (history = history , hide_password = hide_password )
1424
1440
1425
1441
return session .prompt (
1426
1442
message ,
@@ -1431,6 +1447,7 @@ def prompt(
1431
1447
completer = completer ,
1432
1448
complete_in_thread = complete_in_thread ,
1433
1449
is_password = is_password ,
1450
+ # hide_password=hide_password,
1434
1451
key_bindings = key_bindings ,
1435
1452
bottom_toolbar = bottom_toolbar ,
1436
1453
style = style ,
0 commit comments