Skip to content

Commit 9d448a6

Browse files
committed
Go over set style/highlight. Add "show styles".
1 parent 2054479 commit 9d448a6

12 files changed

Lines changed: 102 additions & 61 deletions

File tree

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ repos:
99
stages: [commit]
1010
- id: end-of-file-fixer
1111
stages: [commit]
12-
- repo: https://github.com/pycqa/isort
13-
rev: 5.13.2
14-
hooks:
15-
- id: isort
16-
stages: [commit]
17-
- repo: https://github.com/psf/black
18-
rev: 23.12.1
19-
hooks:
20-
- id: black
21-
language_version: python3
22-
stages: [commit]
23-
exclude: 'trepan/version.py'
12+
# - repo: https://github.com/pycqa/isort
13+
# rev: 5.13.2
14+
# hooks:
15+
# - id: isort
16+
# stages: [commit]
17+
# - repo: https://github.com/psf/black
18+
# rev: 23.12.1
19+
# hooks:
20+
# - id: black
21+
# language_version: python3
22+
# stages: [commit]
23+
# exclude: 'trepan/version.py'

test/unit/test_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ def test_options():
6363
arg_str = f"{__file__} --style=fafdsaXYZZY"
6464
opts, dbg_opts, sys_argv = process_options("1.3", arg_str.split())
6565
postprocess_options(dbg, opts)
66-
assert dbg.settings["style"] is None
66+
# FIXME figure out a reasonable test for postprocess_options()

trepan/debugger.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, opts=None):
7676
self.mainpyfile = None
7777
self.thread = None
7878
self.eval_string = None
79-
self.settings = {}
79+
self.settings = self.DEFAULT_INIT_OPTS["settings"].copy()
8080

8181
def get_option(key: str) -> Any:
8282
return option_set(opts, key, self.DEFAULT_INIT_OPTS)
@@ -143,10 +143,16 @@ def completer(text: str, state):
143143
pass
144144
return
145145

146-
# The following functions have to be defined before
147-
# DEFAULT_INIT_OPTS which includes references to these.
148-
149-
# FIXME DRY run, run_exec, run_eval.
146+
def complete(self, last_token: str, state: int):
147+
"""
148+
In place expansion of top-level debugger command
149+
for `last_token`` that we are in ``state``.
150+
"""
151+
if hasattr(self.core.processor, "completer"):
152+
string_seen = get_line_buffer() or last_token
153+
results = self.core.processor.completer(string_seen, state)
154+
return results[state]
155+
return
150156

151157
def run(self, cmd, start_opts=None, globals_=None, locals_=None):
152158
"""Run debugger on string `cmd' using builtin function eval
@@ -332,6 +338,9 @@ def restart_argv(self):
332338
"""Return an array that would be execv-ed to restart the program"""
333339
return self.orig_sys_argv or self.program_sys_argv
334340

341+
# The following functions have to be defined before
342+
# DEFAULT_INIT_OPTS which includes references to these.
343+
335344
# Note: has to come after functions listed in ignore_filter.
336345
DEFAULT_INIT_OPTS = {
337346
# What routines will we not trace into?
@@ -364,17 +373,6 @@ def restart_argv(self):
364373
"from_ipython": False,
365374
}
366375

367-
def complete(self, last_token: str, state: int):
368-
"""
369-
In place expansion of top-level debugger command
370-
for `last_token`` that we are in ``state``.
371-
"""
372-
if hasattr(self.core.processor, "completer"):
373-
string_seen = get_line_buffer() or last_token
374-
results = self.core.processor.completer(string_seen, state)
375-
return results[state]
376-
return
377-
378376
pass
379377

380378

@@ -388,9 +386,8 @@ def foo():
388386
pass
389387
return 3
390388

391-
import debugger
392-
393-
d = debugger.Trepan()
389+
d = Trepan()
390+
print(d.settings)
394391
d.settings["trace"] = True
395392
d.settings["printset"] = tracer.ALL_EVENTS
396393
d.core.step_ignore = -1

trepan/lib/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import trepan.clifns as Mclifns
4040

4141
# Our local modules
42-
from trepan.lib import breakpoint, default, stack as Mstack
42+
from trepan.lib import breakpoint, default
4343
from trepan.lib.stack import count_frames
4444
from trepan.misc import option_set
4545
from trepan.processor import cmdproc as Mcmdproc, trace as Mtrace

trepan/lib/default.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from term_background import is_dark_background
2626

2727
width = computed_displaywidth()
28+
is_dark_bg = is_dark_background()
2829

2930
# Below are the default debugger settings. The debugger object version
3031
# of this may change. A setting is something a user may want to
@@ -81,7 +82,7 @@
8182
# 'plain' : no highlighting
8283
# 'dark' : terminal highlighting for a dark background
8384
# 'light' : terminal highlighting for a light background
84-
"highlight": "dark" if is_dark_background() else "light",
85+
"highlight": "dark" if is_dark_bg else "light",
8586
# Where do we save the history?
8687
"histfile": None,
8788
# Save debugger history?
@@ -107,6 +108,8 @@
107108
# (In the Python they are "class" and "def" statements)
108109
"skip": True,
109110
"step_ignore": 0,
111+
# Pygments style
112+
"style": "zenburn" if is_dark_bg else "tango",
110113
# Location to put temporary decompiled python files.
111114
# If value is None, use Python's defaults
112115
"tempdir": None,

trepan/lib/disassemble.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from typing import Callable
1111

12+
from pygments.token import Comment
13+
1214
from xdis import (
1315
IS_PYPY,
1416
Bytecode,
@@ -22,7 +24,6 @@
2224

2325
from trepan.lib.format import (
2426
Arrow,
25-
Comment,
2627
Details,
2728
Hex,
2829
Integer,

trepan/lib/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
Operator,
3838
String,
3939
Token,
40-
Text
4140
)
4241
from trepan.lib.default import DEBUGGER_SETTINGS
4342

@@ -78,6 +77,7 @@
7877
color_scheme[Generic.Strong] = ("*black*", "*white*")
7978
color_scheme[Name.Variable] = ("_black_", "_white_")
8079
color_scheme[Generic.Emph] = ("blue", "brightcyan")
80+
color_scheme[Token.Comment] = ("magenta", "yellow")
8181

8282
# Assume pygments has fixed up the horrible atom colors
8383
# FIXME: change some horrible colors under atom dark

trepan/options.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ def postprocess_options(dbg, opts):
381381
else:
382382
dbg.settings["highlight"] = "plain"
383383

384-
dbg.settings["style"] = None
385384
if getattr(opts, "style") and opts.style != "none":
386385
style_names = sorted(list(STYLE_MAP.keys()))
387386
if opts.style in style_names:

trepan/processor/command/list.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import linecache
1919
import os.path as osp
2020
import sys
21+
from trepan.processor.cmd_addrlist import INVALID_PARSE_LIST
2122

2223
import pyficache
2324

@@ -88,6 +89,8 @@ def run(self, args):
8889
dbg_obj = self.core.debugger
8990
listsize = dbg_obj.settings["listsize"]
9091
filename, first, last = parse_list_cmd(proc, args, listsize)
92+
if (filename, first, last) == INVALID_PARSE_LIST:
93+
return
9194
curframe = proc.curframe
9295
if filename is None:
9396
return
@@ -129,8 +132,9 @@ def run(self, args):
129132
"strip_nl": False,
130133
}
131134

132-
if "style" in self.settings:
133-
opts["style"] = self.settings["style"]
135+
for field in ("highlight", "style"):
136+
if field in self.settings:
137+
opts[field] = self.settings[field]
134138

135139
if first <= 0:
136140
first = 1
@@ -189,9 +193,9 @@ def doit(cmd, args):
189193
cmd.run(args)
190194

191195
from trepan.processor.cmdproc import CommandProcessor
192-
from trepan.processor.command import mock as Mmock
196+
from trepan.processor.command.mock import MockDebugger
193197

194-
d = Mmock.MockDebugger()
198+
d = MockDebugger()
195199
cmdproc = CommandProcessor(d.core)
196200
cmdproc.frame = sys._getframe()
197201
cmdproc.setup()
@@ -200,8 +204,8 @@ def doit(cmd, args):
200204
print("--" * 10)
201205
# doit(lcmd, ['list'])
202206

203-
# doit(lcmd, ['list', __file__ + ':10'])
204-
# print('--' * 10)
207+
doit(lcmd, ['list', __file__ + ':5'])
208+
print('--' * 10)
205209

206210
# doit(lcmd, ['list', 'os:10'])
207211
# print('--' * 10)

trepan/processor/command/set_subcmd/style.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
#
44

55
from pygments.styles import STYLE_MAP
6+
from trepan.lib.complete import complete_token
7+
from trepan.processor.command.base_subcmd import DebuggerSubcommand
68

79
style_names = sorted(list(STYLE_MAP.keys()))
810

9-
from trepan.lib import complete as Mcomplete
10-
11-
# Our local modules
12-
from trepan.processor.command.base_subcmd import DebuggerSubcommand
13-
1411

1512
class SetStyle(DebuggerSubcommand):
1613
"""**set style** [*pygments-style*]
@@ -35,23 +32,21 @@ class SetStyle(DebuggerSubcommand):
3532
`show style`, `set highlight`"""
3633

3734
def complete(self, prefix):
38-
return Mcomplete.complete_token(style_names, prefix)
35+
return complete_token(style_names, prefix)
3936

4037
in_list = True
4138
min_abbrev = len("sty")
4239
short_help = "Set the pygments style"
4340

4441
def run(self, args):
4542
if len(args) == 0:
46-
self.section("style names: ")
47-
self.msg(self.columnize_commands(style_names))
48-
return
43+
return self.proc.commands["show"].cmds.subcmds["styles"].run([])
4944
if args[0] == "none":
5045
self.debugger.settings[self.name] = None
5146
return
5247

5348
if args[0] not in style_names:
54-
self.errmsg("style name '%s' not valid. valid names are: " % args[0])
49+
self.errmsg(f"style name '{args[0]}' not valid. valid names are: ")
5550
self.msg(self.columnize_commands(style_names))
5651
return
5752

@@ -61,10 +56,8 @@ def run(self, args):
6156
pass
6257

6358

64-
# if __name__ == '__main__':
65-
# from trepan.processor.command.set_subcmd import __demo_helper__ as Mhelper
66-
# sub = Mhelper.demo_run(SetWidth)
67-
# d = sub.proc.debugger
68-
# sub.run(['emacs'])
69-
# print(d.settings['emacs'])
70-
# pass
59+
if __name__ == '__main__':
60+
from trepan.processor.command.set_subcmd.__demo_helper__ import demo_run
61+
demo_run(SetStyle, ["emacs"])
62+
demo_run(SetStyle, [])
63+
pass

0 commit comments

Comments
 (0)