|
40 | 40 | import trepan.misc as Mmisc |
41 | 41 | from trepan.interfaces.script import ScriptInterface |
42 | 42 | from trepan.lib.bytecode import is_class_def, is_def_stmt |
43 | | -from trepan.processor.complete import completer |
44 | 43 | from trepan.processor.print import print_location |
| 44 | +from trepan.processor.complete_rl import completer |
45 | 45 | from trepan.vprocessor import Processor |
46 | 46 |
|
47 | 47 |
|
@@ -232,6 +232,36 @@ def get_option_fn(key): |
232 | 232 | self.queue_startfile(init_cmdfile) |
233 | 233 |
|
234 | 234 | self.set_prompt() |
| 235 | + |
| 236 | + # Set up prompt-toolkit completion |
| 237 | + if self.is_using_prompt_toolkit(): |
| 238 | + from trepan.processor.complete_ptk import Trepan3KCompleter |
| 239 | + |
| 240 | + trepan3k_completer = Trepan3KCompleter( |
| 241 | + list(self.commands.keys()), self.aliases |
| 242 | + ) |
| 243 | + |
| 244 | + for cmd, cmd_obj in self.commands.items(): |
| 245 | + if hasattr(cmd_obj, "cmds") and hasattr(cmd_obj.cmds, "cmdlist"): |
| 246 | + trepan3k_completer.add_completions(cmd, sorted(cmd_obj.cmds.cmdlist)) |
| 247 | + for subcmd_name, subcmd_obj in cmd_obj.cmds.subcmds.items(): |
| 248 | + subcmd_key = f"{cmd} {subcmd_name}" |
| 249 | + if hasattr(subcmd_obj, "completion_choices"): |
| 250 | + trepan3k_completer.add_completions( |
| 251 | + subcmd_key, sorted(subcmd_obj.completion_choices) |
| 252 | + ) |
| 253 | + pass |
| 254 | + pass |
| 255 | + elif hasattr(cmd_obj, "completion_choices"): |
| 256 | + trepan3k_completer.add_completions( |
| 257 | + cmd, sorted(cmd_obj.completion_choices) |
| 258 | + ) |
| 259 | + pass |
| 260 | + pass |
| 261 | + |
| 262 | + for i in self.intf: |
| 263 | + if i.input.session is not None: |
| 264 | + i.input.session.completer = trepan3k_completer |
235 | 265 | return |
236 | 266 |
|
237 | 267 | def _saferepr(self, str, maxwidth=None): |
@@ -268,7 +298,7 @@ def set_prompt(self, prompt="trepan3k"): |
268 | 298 | pass |
269 | 299 | self.prompt_str = f"{'(' * self.debug_nest}{prompt}{')' * self.debug_nest}" |
270 | 300 | highlight = self.debugger.settings["highlight"] |
271 | | - using_prompt_toolkit = self.intf[-1].input.session is not None |
| 301 | + using_prompt_toolkit = self.is_using_prompt_toolkit() |
272 | 302 | if not using_prompt_toolkit and highlight and highlight in ("light", "dark"): |
273 | 303 | self.prompt_str = colorize("underline", self.prompt_str) |
274 | 304 | self.prompt_str += " " |
@@ -481,6 +511,9 @@ def getval(self, arg, locals=None): |
481 | 511 | raise |
482 | 512 | return |
483 | 513 |
|
| 514 | + def is_using_prompt_toolkit(self) -> bool: |
| 515 | + return self.intf[-1].input.session is not None |
| 516 | + |
484 | 517 | def ok_for_running(self, cmd_obj, name, nargs): |
485 | 518 | """We separate some of the common debugger command checks here: |
486 | 519 | whether it makes sense to run the command in this execution state, |
|
0 commit comments