Skip to content

Commit aaefc23

Browse files
authored
Add "show history" subcommand (#66)
1 parent 5c13530 commit aaefc23

7 files changed

Lines changed: 96 additions & 9 deletions

File tree

trepan/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def run_exec(statement, debug_opts=None, start_opts=None, globals_=None, locals_
131131

132132

133133
def debug(
134-
dbg_opts=None,
134+
dbg_opts={},
135135
start_opts=None,
136136
post_mortem: bool = True,
137137
step_ignore: int = 1,

trepan/inout/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def close(self):
5959
return
6060

6161
def use_history(self):
62-
return self.use_raw
62+
return self.use_raw or self.session
6363

6464
def open(self, inp, opts={}):
6565
"""Use this to set where to read from.

trepan/interfaces/user.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
DEFAULT_USER_SETTINGS = {
3333
"histfile": histfile, # Where do we save the history?
34+
"histsize": 50, # How many history items do we save
3435
"complete": None, # Function which handles tab completion, or None
3536
}
3637

@@ -59,6 +60,7 @@ def __init__(self, inp=None, out=None, opts={}):
5960
self.input = inp or DebuggerUserInput(self.user_opts.get("input", {}), self.user_opts)
6061
self.output = out or DebuggerUserOutput()
6162
self.debugger_name = self.user_opts.get("debugger_name", "trepan3k")
63+
self.histfile = None
6264

6365
if self.input.use_history():
6466
self.complete = self.user_opts["complete"]
@@ -76,7 +78,7 @@ def __init__(self, inp=None, out=None, opts={}):
7678
# PyPy read_history_file fails
7779
return
7880
try:
79-
set_history_length(50)
81+
set_history_length(DEFAULT_USER_SETTINGS["histsize"])
8082
except Exception:
8183
pass
8284
atexit.register(self.user_write_history_file)

trepan/processor/command/info_subcmd/break.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2012-2013, 2015, 2018 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2009, 2012-2013, 2015, 2018, 2024
3+
# Rocky Bernstein <rocky@gnu.org>
34
#
45
# This program is free software: you can redistribute it and/or modify
56
# it under the terms of the GNU General Public License as published by
@@ -54,7 +55,7 @@ class InfoBreak(Mbase_subcmd.DebuggerSubcommand):
5455
5556
"""
5657

57-
min_abbrev = 1 # Min is info b
58+
min_abbrev = len("b")
5859
need_stack = False
5960
short_help = "Status of user-settable breakpoints"
6061

trepan/processor/command/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self):
4141
self.io = MockIO()
4242
self.output = MockIO()
4343
self.debugger_name = "trepan3k"
44+
self.histfile = "/tmp/.trepanrc"
4445
return
4546

4647
def confirm(self, msg, default):
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2024 Rocky Bernstein <rocky@gnu.org>
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# Our local modules
18+
from trepan.lib.complete import complete_token
19+
from trepan.processor.command.base_subcmd import DebuggerSubcommand
20+
21+
from trepan.interfaces.user import DEFAULT_USER_SETTINGS
22+
23+
class ShowHistory(DebuggerSubcommand):
24+
"""**show history** [ *filename* | *save* | *size* ]
25+
26+
Show history information
27+
28+
options include:
29+
* size: Show the size of the command history.
30+
* filename Show the filename in which to record the command historyh.
31+
32+
Examples:
33+
--------
34+
(trepan3k) show history size
35+
The size of the command history is 50.
36+
37+
(trepan3k) show history
38+
history filename: The filename in which to record the command history is "/home/joe/.trepan3k_hist".
39+
history save: Saving of the history record on exit is on.
40+
history size: The size of the command history is 50.
41+
"""
42+
43+
min_abbrev = len("his")
44+
need_stack = False
45+
short_help = "Generic command for showing command history parameters"
46+
47+
def complete(self, prefix):
48+
return complete_token(("filename", "save", "size"))
49+
50+
def run(self, args):
51+
opts = self.debugger.settings
52+
show_prefix = False
53+
if len(args) == 0:
54+
args = ("filename", "save", "size")
55+
show_prefix = True
56+
57+
for arg in args:
58+
prefix = f"history {arg}: " if show_prefix else ""
59+
if arg == "filename":
60+
self.msg(f'{prefix}The filename in which to record the command history is "{self.proc.intf[-1].histfile}".')
61+
elif arg == "save":
62+
self.msg(f'{prefix}Saving of the history record on exit is {"on" if opts.get("hist_save", False) else "off"}.')
63+
elif arg == "size":
64+
self.msg(f'{prefix}The size of the command history is {DEFAULT_USER_SETTINGS["histsize"]}.')
65+
else:
66+
self.errmsg(f"Undefined show history command: {arg}")
67+
pass
68+
return
69+
70+
pass
71+
72+
73+
if __name__ == "__main__":
74+
from trepan.processor.command.set_subcmd.__demo_helper__ import demo_run
75+
76+
sub = demo_run(ShowHistory, [])
77+
d = sub.proc.debugger
78+
sub.run([])
79+
sub.run(["filename"])
80+
sub.run(["save"])
81+
sub.run(["size"])
82+
sub.run(["foo"])
83+
pass

trepan/processor/command/show_subcmd/style.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
style_names = sorted(list(STYLE_MAP.keys()))
1313

1414

15-
def complete(self, prefix):
16-
return complete_token(style_names)
17-
18-
1915
class ShowStyle(DebuggerSubcommand):
2016
"""**show style* *pygments-style*
2117
@@ -30,6 +26,10 @@ class ShowStyle(DebuggerSubcommand):
3026
min_abbrev = len("sty")
3127
short_help = "Set the pygments style"
3228

29+
def complete(self, prefix):
30+
return complete_token(style_names)
31+
32+
3333
def run(self, args):
3434
if len(args) != 0:
3535
self.errmsg("Expecting no args")

0 commit comments

Comments
 (0)