@@ -157,75 +157,139 @@ def parse(self, argument_string):
157157 # Return new Arguments with converted options
158158 return Arguments (arguments .expressions , arguments .flags , converted_options )
159159
160- def help_text (self , command_name ):
160+ def help_text (self , command_name , terminal = None ):
161161 """Generate help text from usage specification.
162162
163163 Args:
164164 command_name: Name of the command (e.g., "rb-object-print")
165+ terminal: Optional terminal for colored output
165166
166167 Returns:
167168 Formatted help string with usage, parameters, options, and flags
168169 """
169- lines = [self .summary , "" ]
170+ # Import format if we have a terminal
171+ if terminal :
172+ import format as fmt
173+ else :
174+ fmt = None
175+ # Summary with color
176+ if terminal :
177+ lines = [terminal .print (fmt .bold , self .summary , fmt .reset ), "" ]
178+ else :
179+ lines = [self .summary , "" ]
170180
171181 # Build usage line
172- usage_parts = [command_name ]
182+ usage_parts = [command_name ] if not terminal else [terminal .print (fmt .bold , command_name , fmt .reset )]
183+
173184 for param_name , _ in self .parameters :
174- usage_parts .append (f"<{ param_name } >" )
185+ if terminal :
186+ usage_parts .append (terminal .print (fmt .dim , f"<{ param_name } >" , fmt .reset ))
187+ else :
188+ usage_parts .append (f"<{ param_name } >" )
175189
176190 # Add option placeholders
177191 for option_name in self .options .keys ():
178- usage_parts .append (f"[--{ option_name } N]" )
192+ placeholder = f"[--{ option_name } N]"
193+ if terminal :
194+ usage_parts .append (terminal .print (fmt .dim , placeholder , fmt .reset ))
195+ else :
196+ usage_parts .append (placeholder )
179197
180198 # Add flag placeholders
181199 for flag_name , _ in self .flags :
182- usage_parts .append (f"[--{ flag_name } ]" )
200+ placeholder = f"[--{ flag_name } ]"
201+ if terminal :
202+ usage_parts .append (terminal .print (fmt .dim , placeholder , fmt .reset ))
203+ else :
204+ usage_parts .append (placeholder )
183205
184206 lines .append (f"Usage: { ' ' .join (usage_parts )} " )
185207 lines .append ("" )
186208
187209 # Parameter descriptions
188210 if self .parameters :
189- lines .append ("Parameters:" )
211+ if terminal :
212+ lines .append (terminal .print (fmt .title , "Parameters:" , fmt .reset ))
213+ else :
214+ lines .append ("Parameters:" )
215+
190216 for param_name , param_desc in self .parameters :
191- if param_desc :
192- lines .append (f" { param_name :<15} { param_desc } " )
217+ if terminal :
218+ param_str = terminal .print (fmt .symbol , param_name , fmt .reset )
219+ if param_desc :
220+ lines .append (f" { param_str :<15} { param_desc } " )
221+ else :
222+ lines .append (f" { param_str } " )
193223 else :
194- lines .append (f" { param_name } " )
224+ if param_desc :
225+ lines .append (f" { param_name :<15} { param_desc } " )
226+ else :
227+ lines .append (f" { param_name } " )
195228 lines .append ("" )
196229
197230 # Option descriptions
198231 if self .options :
199- lines .append ("Options:" )
232+ if terminal :
233+ lines .append (terminal .print (fmt .title , "Options:" , fmt .reset ))
234+ else :
235+ lines .append ("Options:" )
236+
200237 for option_name , opt_spec in self .options .items ():
201238 opt_type , opt_default = opt_spec [0 ], opt_spec [1 ]
202239 opt_desc = opt_spec [2 ] if len (opt_spec ) > 2 else None
203240
204241 type_str = opt_type .__name__ if hasattr (opt_type , '__name__' ) else str (opt_type )
205242 default_str = f" (default: { opt_default } )" if opt_default is not None else ""
206243
244+ if terminal :
245+ opt_str = terminal .print (fmt .symbol , f"--{ option_name } " , fmt .reset )
246+ type_part = terminal .print (fmt .dim , f" <{ type_str } >" , fmt .reset )
247+ else :
248+ opt_str = f"--{ option_name } "
249+ type_part = f" <{ type_str } >"
250+
207251 if opt_desc :
208- lines .append (f" -- { option_name } < { type_str } > { default_str } " )
252+ lines .append (f" { opt_str } { type_part } { default_str } " )
209253 lines .append (f" { opt_desc } " )
210254 else :
211- lines .append (f" -- { option_name } < { type_str } > { default_str } " )
255+ lines .append (f" { opt_str } { type_part } { default_str } " )
212256 lines .append ("" )
213257
214258 # Flag descriptions
215259 if self .flags :
216- lines .append ("Flags:" )
260+ if terminal :
261+ lines .append (terminal .print (fmt .title , "Flags:" , fmt .reset ))
262+ else :
263+ lines .append ("Flags:" )
264+
217265 for flag_name , flag_desc in self .flags :
218- if flag_desc :
219- lines .append (f" --{ flag_name :<15} { flag_desc } " )
266+ if terminal :
267+ flag_str = terminal .print (fmt .symbol , f"--{ flag_name } " , fmt .reset )
268+ if flag_desc :
269+ lines .append (f" { flag_str :<15} { flag_desc } " )
270+ else :
271+ lines .append (f" { flag_str } " )
220272 else :
221- lines .append (f" --{ flag_name } " )
273+ if flag_desc :
274+ lines .append (f" --{ flag_name :<15} { flag_desc } " )
275+ else :
276+ lines .append (f" --{ flag_name } " )
222277 lines .append ("" )
223278
224279 # Examples section
225280 if self .examples :
226- lines .append ("Examples:" )
281+ if terminal :
282+ lines .append (terminal .print (fmt .title , "Examples:" , fmt .reset ))
283+ else :
284+ lines .append ("Examples:" )
285+
227286 for example_cmd , example_desc in self .examples :
228- lines .append (f" { example_cmd } " )
287+ if terminal :
288+ cmd_str = terminal .print (fmt .dim , f" { example_cmd } " , fmt .reset )
289+ lines .append (cmd_str )
290+ else :
291+ lines .append (f" { example_cmd } " )
292+
229293 if example_desc :
230294 lines .append (f" { example_desc } " )
231295 lines .append ("" )
0 commit comments