Skip to content

Commit 53799b6

Browse files
Fix printing implementation.
1 parent a6e4f5a commit 53799b6

File tree

14 files changed

+156
-213
lines changed

14 files changed

+156
-213
lines changed

data/toolbox/command.py

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -157,55 +157,55 @@ 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, terminal):
161-
"""Generate help text from usage specification.
160+
def print_to(self, terminal, command_name):
161+
"""Print help text from usage specification.
162162
163163
Args:
164-
command_name: Name of the command (e.g., "rb-print")
165164
terminal: Terminal for colored output
166-
167-
Returns:
168-
Formatted help string with usage, parameters, options, and flags
165+
command_name: Name of the command (e.g., "rb-print")
169166
"""
170167
import format as fmt
171168

172169
# Summary with color
173-
lines = [terminal.print(fmt.bold, self.summary, fmt.reset), ""]
170+
terminal.print(fmt.bold, self.summary, fmt.reset)
171+
terminal.print()
174172

175-
# Build usage line
176-
usage_parts = [terminal.print(fmt.bold, command_name, fmt.reset)]
173+
# Print usage line
174+
terminal.print("Usage: ", end='')
175+
terminal.print(fmt.bold, command_name, fmt.reset, end='')
177176

178177
for param_name, _ in self.parameters:
179-
usage_parts.append(terminal.print(fmt.placeholder, f"<{param_name}>", fmt.reset))
178+
terminal.print(' ', end='')
179+
terminal.print(fmt.placeholder, f"<{param_name}>", fmt.reset, end='')
180180

181181
# Add option placeholders
182182
for option_name in self.options.keys():
183-
opt_placeholder = f"[--{option_name} N]"
184-
usage_parts.append(terminal.print(fmt.placeholder, opt_placeholder, fmt.reset))
183+
terminal.print(' ', end='')
184+
terminal.print(fmt.placeholder, f"[--{option_name} N]", fmt.reset, end='')
185185

186186
# Add flag placeholders
187187
for flag_name, _ in self.flags:
188-
flag_placeholder = f"[--{flag_name}]"
189-
usage_parts.append(terminal.print(fmt.placeholder, flag_placeholder, fmt.reset))
188+
terminal.print(' ', end='')
189+
terminal.print(fmt.placeholder, f"[--{flag_name}]", fmt.reset, end='')
190190

191-
lines.append(f"Usage: {' '.join(usage_parts)}")
192-
lines.append("")
191+
terminal.print()
192+
terminal.print()
193193

194194
# Parameter descriptions
195195
if self.parameters:
196-
lines.append(terminal.print(fmt.title, "Parameters:", fmt.reset))
196+
terminal.print(fmt.title, "Parameters:", fmt.reset)
197197

198198
for param_name, param_desc in self.parameters:
199-
param_str = terminal.print(fmt.symbol, param_name, fmt.reset)
199+
terminal.print(" ", fmt.symbol, param_name, fmt.reset, end='')
200200
if param_desc:
201-
lines.append(f" {param_str:<15} {param_desc}")
201+
terminal.print(f" - {param_desc}")
202202
else:
203-
lines.append(f" {param_str}")
204-
lines.append("")
203+
terminal.print()
204+
terminal.print()
205205

206206
# Option descriptions
207207
if self.options:
208-
lines.append(terminal.print(fmt.title, "Options:", fmt.reset))
208+
terminal.print(fmt.title, "Options:", fmt.reset)
209209

210210
for option_name, opt_spec in self.options.items():
211211
opt_type, opt_default = opt_spec[0], opt_spec[1]
@@ -214,40 +214,34 @@ def help_text(self, command_name, terminal):
214214
type_str = opt_type.__name__ if hasattr(opt_type, '__name__') else str(opt_type)
215215
default_str = f" (default: {opt_default})" if opt_default is not None else ""
216216

217-
opt_str = terminal.print(fmt.symbol, f"--{option_name}", fmt.reset)
218-
type_part = terminal.print(fmt.placeholder, f" <{type_str}>", fmt.reset)
217+
terminal.print(" ", fmt.symbol, f"--{option_name}", fmt.reset, end='')
218+
terminal.print(fmt.placeholder, f" <{type_str}>", fmt.reset, end='')
219+
terminal.print(default_str)
219220

220221
if opt_desc:
221-
lines.append(f" {opt_str}{type_part}{default_str}")
222-
lines.append(f" {opt_desc}")
223-
else:
224-
lines.append(f" {opt_str}{type_part}{default_str}")
225-
lines.append("")
222+
terminal.print(f" {opt_desc}")
223+
terminal.print()
226224

227225
# Flag descriptions
228226
if self.flags:
229-
lines.append(terminal.print(fmt.title, "Flags:", fmt.reset))
227+
terminal.print(fmt.title, "Flags:", fmt.reset)
230228

231229
for flag_name, flag_desc in self.flags:
232-
flag_str = terminal.print(fmt.symbol, f"--{flag_name}", fmt.reset)
230+
terminal.print(" ", fmt.symbol, f"--{flag_name}", fmt.reset, end='')
233231
if flag_desc:
234-
lines.append(f" {flag_str:<15} {flag_desc}")
232+
terminal.print(f" - {flag_desc}")
235233
else:
236-
lines.append(f" {flag_str}")
237-
lines.append("")
234+
terminal.print()
235+
terminal.print()
238236

239237
# Examples section
240238
if self.examples:
241-
lines.append(terminal.print(fmt.title, "Examples:", fmt.reset))
239+
terminal.print(fmt.title, "Examples:", fmt.reset)
242240

243241
for example_cmd, example_desc in self.examples:
244-
cmd_str = terminal.print(fmt.example, f" {example_cmd}", fmt.reset)
245-
lines.append(cmd_str)
242+
terminal.print(fmt.example, f" {example_cmd}", fmt.reset)
246243
if example_desc:
247-
lines.append(f" {example_desc}")
248-
lines.append("")
249-
250-
return '\n'.join(lines)
244+
terminal.print(f" {example_desc}")
251245

252246
class ArgumentParser:
253247
"""Parse GDB command arguments handling nested brackets, quotes, and flags.

data/toolbox/context.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,56 +172,58 @@ def print_info(self, terminal):
172172
errinfo = self.errinfo
173173
has_exception = self.has_exception
174174

175-
print("Execution Context:")
176-
print(f" $ec = ", end='')
177-
print(terminal.print_type_tag('rb_execution_context_t', int(self.ec), None))
175+
terminal.print("Execution Context:")
176+
terminal.print(f" $ec = ", end='')
177+
terminal.print_type_tag('rb_execution_context_t', int(self.ec), None)
178178

179179
# VM Stack info
180180
if vm_stack is not None and vm_stack_size is not None:
181-
print(f" VM Stack: ", end='')
182-
print(terminal.print_type_tag('VALUE', int(vm_stack), f'size={vm_stack_size}'))
181+
terminal.print(f" VM Stack: ", end='')
182+
terminal.print_type_tag('VALUE', int(vm_stack), f'size={vm_stack_size}')
183183
else:
184-
print(f" VM Stack: <unavailable>")
184+
terminal.print(f" VM Stack: <unavailable>")
185185

186186
# Control Frame info
187187
if cfp is not None:
188-
print(f" $cfp = ", end='')
189-
print(terminal.print_type_tag('rb_control_frame_t', int(cfp), None))
188+
terminal.print(f" $cfp = ", end='')
189+
terminal.print_type_tag('rb_control_frame_t', int(cfp), None)
190190
else:
191-
print(f" $cfp = <unavailable>")
191+
terminal.print(f" $cfp = <unavailable>")
192192

193193
# Storage info
194194
if storage is not None and not value.is_nil(storage):
195-
print(f" Storage: ", end='')
196-
print(terminal.print_type_tag('VALUE', int(storage), None))
195+
terminal.print(f" Storage: ", end='')
196+
terminal.print_type_tag('VALUE', int(storage), None)
197197

198198
# Exception info
199199
if has_exception:
200-
print(f" $errinfo = ", end='')
201-
print(terminal.print_type_tag('VALUE', int(errinfo), None))
202-
print(" Exception present!")
200+
terminal.print(" $errinfo = ", end='')
201+
terminal.print_type_tag('VALUE', int(errinfo), None)
202+
terminal.print()
203+
terminal.print(" Exception present!")
203204
else:
204205
errinfo_int = int(errinfo) if errinfo else 0
205206
if errinfo_int == 4: # Qnil
206-
print(" Exception: None")
207+
terminal.print(" Exception: None")
207208
elif errinfo_int == 0: # Qfalse
208-
print(" Exception: None (false)")
209+
terminal.print(" Exception: None (false)")
209210
else:
210-
print(f" Exception: None")
211+
terminal.print(" Exception: None")
211212

212213
# Tag info (for ensure blocks)
213214
try:
214215
tag = self.ec['tag']
215216
tag_int = int(tag)
216217
if tag_int != 0:
217-
print(f" Tag: ", end='')
218-
print(terminal.print_type_tag('rb_vm_tag', tag_int, None))
218+
terminal.print(" Tag: ", end='')
219+
terminal.print_type_tag('rb_vm_tag', tag_int, None)
220+
terminal.print()
219221
try:
220222
retval = tag['retval']
221223
retval_int = int(retval)
222224
is_retval_special = (retval_int & 0x03) != 0 or retval_int == 0
223225
if not is_retval_special:
224-
print(f" $retval available (in ensure block)")
226+
terminal.print(" $retval available (in ensure block)")
225227
except Exception:
226228
pass
227229
except Exception:

data/toolbox/debugger/gdb_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def invoke(self, arg, from_tty):
648648
print(f"Error: {e}")
649649
if self.usage_spec:
650650
print()
651-
print(self.usage_spec.help_text(name, terminal))
651+
self.usage_spec.print_to(terminal, name)
652652
except Exception as e:
653653
print(f"Error: {e}")
654654
import traceback

data/toolbox/debugger/lldb_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def invoke(self, arg, from_tty):
945945
print(f"Error: {e}")
946946
if self.usage_spec:
947947
print()
948-
print(self.usage_spec.help_text(name, terminal))
948+
self.usage_spec.print_to(terminal, name)
949949
except Exception as e:
950950
print(f"Error: {e}")
951951
import traceback

0 commit comments

Comments
 (0)