1010
1111from rich .console import Console
1212from rich .panel import Panel
13- from rich .prompt import Prompt , Confirm
14-
15- from prompt_toolkit import prompt
16- from prompt_toolkit .history import FileHistory
17- from prompt_toolkit .completion import WordCompleter , FuzzyCompleter
13+ from rich .prompt import Confirm
1814
15+ from json_explorer .utils import prompt_input
1916from ...core .config import GeneratorConfig
2017from .config import get_web_api_config , get_strict_config , get_modern_config
2118
@@ -144,6 +141,7 @@ def configure_language_specific(
144141 "JSON tag case style" ,
145142 choices = ["original" , "snake" , "camel" ],
146143 default = "original" ,
144+ console = console ,
147145 )
148146
149147 # Optional fields
@@ -158,16 +156,19 @@ def configure_language_specific(
158156 "Integer type" ,
159157 choices = ["int" , "int32" , "int64" ],
160158 default = "int64" ,
159+ console = console ,
161160 )
162161 go_config ["float_type" ] = self ._input (
163162 "Float type" ,
164163 choices = ["float32" , "float64" ],
165164 default = "float64" ,
165+ console = console ,
166166 )
167167 go_config ["unknown_type" ] = self ._input (
168168 "Unknown type representation" ,
169169 choices = ["interface{}" , "any" ],
170170 default = "interface{}" ,
171+ console = console ,
171172 )
172173
173174 # Advanced options
@@ -176,6 +177,7 @@ def configure_language_specific(
176177 "Time type for timestamps" ,
177178 choices = ["time.Time" , "string" , "int64" ],
178179 default = "time.Time" ,
180+ console = console ,
179181 )
180182
181183 logger .info (f"Go-specific config collected: { len (go_config )} options" )
@@ -284,62 +286,7 @@ def validate_config(self, config: dict[str, Any]) -> list[str]:
284286 # ========================================================================
285287
286288 def _input (self , message : str , default : str | None = None , ** kwargs ) -> str :
287- """
288- User friendly input with optional choices and autocompletion.
289- Falls back to Prompt.ask if prompt_toolkit is unavailable.
290-
291- Args:
292- message: Prompt message.
293- default: Default value if user enters nothing.
294- kwargs: May include 'choices' (list of strings) for tab completion.
295-
296- Returns:
297- User input as string (or default if empty).
298- """
299- choices = kwargs .get ("choices" )
300- try :
301-
302- history = FileHistory (".json_explorer_input_history" )
303-
304- if choices :
305- str_choices = [str (c ) for c in choices ]
306- completer = FuzzyCompleter (WordCompleter (str_choices , ignore_case = True ))
307- # Only show options in prompt, not above it
308- display_message = f"{ message } ({ '/' .join (str_choices )} )"
309-
310- while True :
311- text = prompt (
312- f"{ display_message } > " ,
313- default = default or "" ,
314- history = history ,
315- completer = completer ,
316- complete_while_typing = True ,
317- ).strip ()
318-
319- if not text and default is not None :
320- return default
321-
322- # Exact or case-insensitive match
323- if text in str_choices :
324- return text
325- lowered = text .lower ()
326- ci_matches = [c for c in str_choices if c .lower () == lowered ]
327- if ci_matches :
328- return ci_matches [0 ]
329-
330- # Prefix match
331- prefix_matches = [
332- c for c in str_choices if c .lower ().startswith (lowered )
333- ]
334- if len (prefix_matches ) == 1 :
335- return prefix_matches [0 ]
336-
337- self .console .print (f"[red]Invalid choice: { text } [/red]" )
338-
339- # Free text input
340- return prompt (
341- f"{ message } > " , default = default or "" , history = history
342- ).strip () or (default or "" )
343-
344- except Exception :
345- return self ._input (message , default = default , ** kwargs )
289+ console = kwargs .get ("console" ) or None
290+ return prompt_input (
291+ message , default = default , choices = kwargs .get ("choices" ), console = console
292+ )
0 commit comments