Skip to content

Commit 266308b

Browse files
authored
start prompt_toolkit completion (#68)
* start prompt_toolkit completion * Handle first-two levels of completion * Add 3rd level prompt-toolkit completion... And process "candidate_choices" list in top-level ptk completion
1 parent 37023f6 commit 266308b

25 files changed

Lines changed: 253 additions & 158 deletions

File tree

docs/manpages/trepan3k.rst

Lines changed: 0 additions & 111 deletions
This file was deleted.

test/unit/processor/test_proc_complete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
from xdis import IS_PYPY
88

9-
from trepan.processor import complete as module_complete
9+
from trepan.processor import complete_rl as module_complete
1010
from trepan.processor.command import base_cmd as module_base_command
1111

1212
line_buffer = ""

trepan/inout/input.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
FileHistory = lambda history: None
3636
HTML = lambda string: string
3737
else:
38-
from trepan.inout.prompt_bindkeys import bindings, read_inputrc, read_init_file
38+
from trepan.inout.ptk_bindkeys import bindings, read_inputrc, read_init_file
3939

4040
USER_INPUTRC = os.environ.get("TREPAN3K_INPUTRC", default_configfile("inputrc"))
4141

@@ -119,12 +119,8 @@ def readline(self, use_raw=None, prompt=""):
119119
120120
Note: some user interfaces may decide to arrange to call
121121
DebuggerOutput.write() first with the prompt rather than pass
122-
it here.. If `use_raw' is set raw_input() will be used in that
123-
is supported by the specific input input. If this option is
124-
left None as is normally expected the value from the class
125-
initialization is used.
122+
it here
126123
"""
127-
# FIXME we don't do command completion.
128124
if self.session:
129125
# Using prompt_toolkit
130126
html_prompt = HTML(f"<u>{prompt.strip()}</u> ")
@@ -133,7 +129,6 @@ def readline(self, use_raw=None, prompt=""):
133129

134130
try:
135131
inp = input(prompt)
136-
# import pdb; pdb.set_trace()
137132
return inp
138133
except ValueError:
139134
raise EOFError

trepan/interfaces/user.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,10 @@ def read_command(self, prompt=""):
164164
return line
165165

166166
def readline(self, prompt=""):
167-
use_raw = hasattr(self.input, "use_raw") and self.input.use_raw
168-
if (
169-
use_raw and prompt and len(prompt) > 0 or not self.readline == "prompt_toolkit"
170-
):
171-
self.output.write(prompt)
167+
if not self.readline == "prompt_toolkit":
172168
self.output.flush()
173169
pass
174-
return self.input.readline(prompt=prompt, use_raw=use_raw)
170+
return self.input.readline(prompt=prompt)
175171

176172
pass
177173

trepan/processor/cmdproc.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import trepan.misc as Mmisc
4141
from trepan.interfaces.script import ScriptInterface
4242
from trepan.lib.bytecode import is_class_def, is_def_stmt
43-
from trepan.processor.complete import completer
4443
from trepan.processor.print import print_location
44+
from trepan.processor.complete_rl import completer
4545
from trepan.vprocessor import Processor
4646

4747

@@ -232,6 +232,36 @@ def get_option_fn(key):
232232
self.queue_startfile(init_cmdfile)
233233

234234
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
235265
return
236266

237267
def _saferepr(self, str, maxwidth=None):
@@ -268,7 +298,7 @@ def set_prompt(self, prompt="trepan3k"):
268298
pass
269299
self.prompt_str = f"{'(' * self.debug_nest}{prompt}{')' * self.debug_nest}"
270300
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()
272302
if not using_prompt_toolkit and highlight and highlight in ("light", "dark"):
273303
self.prompt_str = colorize("underline", self.prompt_str)
274304
self.prompt_str += " "
@@ -481,6 +511,9 @@ def getval(self, arg, locals=None):
481511
raise
482512
return
483513

514+
def is_using_prompt_toolkit(self) -> bool:
515+
return self.intf[-1].input.session is not None
516+
484517
def ok_for_running(self, cmd_obj, name, nargs):
485518
"""We separate some of the common debugger command checks here:
486519
whether it makes sense to run the command in this execution state,

trepan/processor/command/break.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009-2010, 2013-2015, 2017-2018, 2020, 2023 Rocky Bernstein
3+
# Copyright (C) 2009-2010, 2013-2015, 2017-2018, 2020, 2023-2024 Rocky Bernstein
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
66
# the Free Software Foundation, either version 3 of the License, or
@@ -18,7 +18,7 @@
1818

1919
# Our local modules
2020
from trepan.processor.command.base_cmd import DebuggerCommand
21-
from trepan.processor.complete import complete_break_linenumber
21+
from trepan.processor.complete_rl import complete_break_linenumber
2222

2323

2424
class BreakCommand(DebuggerCommand):

trepan/processor/command/clear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2015, 2020 Rocky Bernstein
2+
# Copyright (C) 2015, 2020, 2024 Rocky Bernstein
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
1818

1919
# Our local modules
2020
from trepan.processor.command.base_cmd import DebuggerCommand
21-
from trepan.processor.complete import complete_bpnumber
21+
from trepan.processor.complete_rl import complete_bpnumber
2222

2323

2424
class ClearCommand(DebuggerCommand):

trepan/processor/command/condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
from trepan.processor.command.base_cmd import DebuggerCommand
18-
from trepan.processor.complete import complete_bpnumber
18+
from trepan.processor.complete_rl import complete_bpnumber
1919

2020

2121
class ConditionCommand(DebuggerCommand):

trepan/processor/command/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2010, 2012-2015, 2020, 2023 Rocky Bernstein
3+
# Copyright (C) 2010, 2012-2015, 2020, 2023-2024 Rocky Bernstein
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
1919
import threading
2020

2121
from trepan.processor.command.base_cmd import DebuggerCommand
22-
from trepan.processor.complete import complete_identifier
22+
from trepan.processor.complete_rl import complete_identifier
2323

2424

2525
class DebugCommand(DebuggerCommand):

0 commit comments

Comments
 (0)