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