@@ -684,7 +684,7 @@ def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> Non
684684 final_msg = ansi .style_error (final_msg )
685685
686686 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'"
688688 final_msg += ansi .style_warning (warning )
689689
690690 # 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]]]],
28902890 | a list of tuples -> interpreted as (value, text), so
28912891 that the return value can differ from
28922892 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+
28932915 local_opts = opts
28942916 if isinstance (opts , str ):
28952917 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]]]],
29042926 fulloptions .append ((opt [0 ], opt [0 ]))
29052927 for (idx , (_ , text )) in enumerate (fulloptions ):
29062928 self .poutput (' %2d. %s' % (idx + 1 , text ))
2929+
29072930 while True :
29082931 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
29102946
29112947 if rl_type != RlType .NONE :
29122948 hlen = readline .get_current_history_length ()
2913- if hlen >= 1 and response != '' :
2949+ if hlen >= 1 :
29142950 readline .remove_history_item (hlen - 1 )
2915-
29162951 try :
29172952 choice = int (response )
29182953 if choice < 1 :
@@ -2922,6 +2957,7 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
29222957 except (ValueError , IndexError ):
29232958 self .poutput ("{!r} isn't a valid choice. Pick a number between 1 and {}:" .format (
29242959 response , len (fulloptions )))
2960+
29252961 return result
29262962
29272963 def _get_read_only_settings (self ) -> str :
0 commit comments