@@ -684,7 +684,7 @@ def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> Non
684
684
final_msg = ansi .style_error (final_msg )
685
685
686
686
if not self .debug :
687
- warning = "\n To enable full traceback, run the following command: 'set debug true'"
687
+ warning = "\n To enable full traceback, run the following command: 'set debug true'"
688
688
final_msg += ansi .style_warning (warning )
689
689
690
690
# Set apply_style to False since style has already been applied
@@ -2890,6 +2890,28 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
2890
2890
| a list of tuples -> interpreted as (value, text), so
2891
2891
that the return value can differ from
2892
2892
the text advertised to the user """
2893
+
2894
+ completion_disabled = False
2895
+ orig_completer = None
2896
+
2897
+ def disable_completion ():
2898
+ """Turn off completion during the select input line"""
2899
+ nonlocal orig_completer
2900
+ nonlocal completion_disabled
2901
+
2902
+ if rl_type != RlType .NONE and not completion_disabled :
2903
+ orig_completer = readline .get_completer ()
2904
+ readline .set_completer (lambda * args , ** kwargs : None )
2905
+ completion_disabled = True
2906
+
2907
+ def enable_completion ():
2908
+ """Restore tab completion when select is done reading input"""
2909
+ nonlocal completion_disabled
2910
+
2911
+ if rl_type != RlType .NONE and completion_disabled :
2912
+ readline .set_completer (orig_completer )
2913
+ completion_disabled = False
2914
+
2893
2915
local_opts = opts
2894
2916
if isinstance (opts , str ):
2895
2917
local_opts = list (zip (opts .split (), opts .split ()))
@@ -2904,15 +2926,28 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
2904
2926
fulloptions .append ((opt [0 ], opt [0 ]))
2905
2927
for (idx , (_ , text )) in enumerate (fulloptions ):
2906
2928
self .poutput (' %2d. %s' % (idx + 1 , text ))
2929
+
2907
2930
while True :
2908
2931
safe_prompt = rl_make_safe_prompt (prompt )
2909
- response = input (safe_prompt )
2932
+
2933
+ try :
2934
+ with self .sigint_protection :
2935
+ disable_completion ()
2936
+ response = input (safe_prompt )
2937
+ except EOFError :
2938
+ response = ''
2939
+ self .poutput ('\n ' , end = '' )
2940
+ finally :
2941
+ with self .sigint_protection :
2942
+ enable_completion ()
2943
+
2944
+ if not response :
2945
+ continue
2910
2946
2911
2947
if rl_type != RlType .NONE :
2912
2948
hlen = readline .get_current_history_length ()
2913
- if hlen >= 1 and response != '' :
2949
+ if hlen >= 1 :
2914
2950
readline .remove_history_item (hlen - 1 )
2915
-
2916
2951
try :
2917
2952
choice = int (response )
2918
2953
if choice < 1 :
@@ -2922,6 +2957,7 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
2922
2957
except (ValueError , IndexError ):
2923
2958
self .poutput ("{!r} isn't a valid choice. Pick a number between 1 and {}:" .format (
2924
2959
response , len (fulloptions )))
2960
+
2925
2961
return result
2926
2962
2927
2963
def _get_read_only_settings (self ) -> str :
0 commit comments