Skip to content

Commit

Permalink
start prompt_toolkit completion
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Nov 11, 2024
1 parent c843903 commit f0011e6
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 398 deletions.
111 changes: 0 additions & 111 deletions docs/manpages/trepan3k.rst

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/processor/test_proc_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from xdis import IS_PYPY

from trepan.processor import complete as module_complete
from trepan.processor import complete_rl as module_complete
from trepan.processor.command import base_cmd as module_base_command

line_buffer = ""
Expand Down
9 changes: 2 additions & 7 deletions trepan/inout/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
FileHistory = lambda history: None
HTML = lambda string: string
else:
from trepan.inout.prompt_bindkeys import bindings, read_inputrc, read_init_file
from trepan.inout.ptk_bindkeys import bindings, read_inputrc, read_init_file

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

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

try:
inp = input(prompt)
# import pdb; pdb.set_trace()
return inp
except ValueError:
raise EOFError
Expand Down
80 changes: 0 additions & 80 deletions trepan/inout/prompt_bindkeys.py

This file was deleted.

8 changes: 2 additions & 6 deletions trepan/interfaces/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,10 @@ def read_command(self, prompt=""):
return line

def readline(self, prompt=""):
use_raw = hasattr(self.input, "use_raw") and self.input.use_raw
if (
use_raw and prompt and len(prompt) > 0 or not self.readline == "prompt_toolkit"
):
self.output.write(prompt)
if not self.readline == "prompt_toolkit":
self.output.flush()
pass
return self.input.readline(prompt=prompt, use_raw=use_raw)
return self.input.readline(prompt=prompt)

pass

Expand Down
14 changes: 12 additions & 2 deletions trepan/processor/cmdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import trepan.misc as Mmisc
from trepan.interfaces.script import ScriptInterface
from trepan.lib.bytecode import is_class_def, is_def_stmt
from trepan.processor.complete import completer
from trepan.processor.print import print_location
from trepan.processor.complete_rl import completer
from trepan.vprocessor import Processor


Expand Down Expand Up @@ -232,6 +232,12 @@ def get_option_fn(key):
self.queue_startfile(init_cmdfile)

self.set_prompt()
if self.is_using_prompt_toolkit:
from trepan.processor.complete_ptk import Trepan3KCompleter
trepan3k_completer = Trepan3KCompleter(self.commands.keys())
for i in self.intf:
if i.input.session is not None:
i.input.session.completer = trepan3k_completer
return

def _saferepr(self, str, maxwidth=None):
Expand Down Expand Up @@ -268,7 +274,7 @@ def set_prompt(self, prompt="trepan3k"):
pass
self.prompt_str = f"{'(' * self.debug_nest}{prompt}{')' * self.debug_nest}"
highlight = self.debugger.settings["highlight"]
using_prompt_toolkit = self.intf[-1].input.session is not None
using_prompt_toolkit = self.is_using_prompt_toolkit()
if not using_prompt_toolkit and highlight and highlight in ("light", "dark"):
self.prompt_str = colorize("underline", self.prompt_str)
self.prompt_str += " "
Expand Down Expand Up @@ -481,6 +487,10 @@ def getval(self, arg, locals=None):
raise
return

def is_using_prompt_toolkit(self) -> bool:
return self.intf[-1].input.session is not None


def ok_for_running(self, cmd_obj, name, nargs):
"""We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
Expand Down
4 changes: 2 additions & 2 deletions trepan/processor/command/break.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2010, 2013-2015, 2017-2018, 2020, 2023 Rocky Bernstein
# Copyright (C) 2009-2010, 2013-2015, 2017-2018, 2020, 2023-2024 Rocky Bernstein
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -18,7 +18,7 @@

# Our local modules
from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_break_linenumber
from trepan.processor.complete_rl import complete_break_linenumber


class BreakCommand(DebuggerCommand):
Expand Down
4 changes: 2 additions & 2 deletions trepan/processor/command/clear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015, 2020 Rocky Bernstein
# Copyright (C) 2015, 2020, 2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,7 @@

# Our local modules
from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_bpnumber
from trepan.processor.complete_rl import complete_bpnumber


class ClearCommand(DebuggerCommand):
Expand Down
2 changes: 1 addition & 1 deletion trepan/processor/command/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_bpnumber
from trepan.processor.complete_rl import complete_bpnumber


class ConditionCommand(DebuggerCommand):
Expand Down
4 changes: 2 additions & 2 deletions trepan/processor/command/debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010, 2012-2015, 2020, 2023 Rocky Bernstein
# Copyright (C) 2010, 2012-2015, 2020, 2023-2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@
import threading

from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_identifier
from trepan.processor.complete_rl import complete_identifier


class DebugCommand(DebuggerCommand):
Expand Down
4 changes: 2 additions & 2 deletions trepan/processor/command/delete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2013, 2015, 2017, 2020 Rocky Bernstein
# Copyright (C) 2009, 2013, 2015, 2017, 2020, 2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -16,7 +16,7 @@

# Our local modules
from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_bpnumber
from trepan.processor.complete_rl import complete_bpnumber


class DeleteCommand(DebuggerCommand):
Expand Down
2 changes: 1 addition & 1 deletion trepan/processor/command/disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Our local modules
from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_bpnumber
from trepan.processor.complete_rl import complete_bpnumber


class DisableCommand(DebuggerCommand):
Expand Down
4 changes: 2 additions & 2 deletions trepan/processor/command/display.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2013, 2015-2016, 2020 Rocky Bernstein
# Copyright (C) 2009-2013, 2015-2016, 2020, 2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -16,7 +16,7 @@

# Our local modules
from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.complete import complete_id_and_builtins
from trepan.processor.complete_rl import complete_id_and_builtins


class DisplayCommand(DebuggerCommand):
Expand Down
Loading

0 comments on commit f0011e6

Please sign in to comment.