Skip to content

Commit 2054479

Browse files
committed
Fix some of the funky terminal highight problems..
more remain. Doc asmft
1 parent 0e242f9 commit 2054479

5 files changed

Lines changed: 56 additions & 16 deletions

File tree

docs/commands/data/disassemble.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ in addition you can also use:
2424
With a class, method, function, pyc-file, code or string argument
2525
disassemble that.
2626

27+
Assembly output format is be controlled by the setting of ``set
28+
asmfmt``. Output formats are those described the ``xdis`` ``pydisasm``
29+
disassembler.
30+
2731
Examples
2832
++++++++
2933

@@ -43,4 +47,6 @@ Examples
4347

4448
.. seealso::
4549

46-
:ref:`help syntax arange <syntax_arange>` for the specification of a address range :ref:`deparse <deparse>`, :ref:`list <list>`, :ref:`info pc <info_pc>`
50+
:ref:`help syntax arange <syntax_arange>` for the specification of an
51+
address range :ref:`deparse <deparse>`, :ref:`list <list>`,
52+
:ref:`info pc <info_pc>`, and :ref:`set asmfmt <set_asmfmt>`.

trepan/lib/bytecode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def next_opcode(code, offset):
5656
pass
5757

5858

59-
def next_linestart(co, offset, count=1):
59+
def next_linestart(co, offset: int, count=1) -> int:
6060
code = co.co_code
6161

6262
linestarts = dict(opcode_module.findlinestarts(co))

trepan/lib/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
# 'plain' : no highlighting
8282
# 'dark' : terminal highlighting for a dark background
8383
# 'light' : terminal highlighting for a light background
84-
"highlight": is_dark_background(),
84+
"highlight": "dark" if is_dark_background() else "light",
8585
# Where do we save the history?
8686
"histfile": None,
8787
# Save debugger history?

trepan/lib/format.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,47 @@
3737
Operator,
3838
String,
3939
Token,
40+
Text
4041
)
41-
from pygments.util import get_choice_opt
42+
from trepan.lib.default import DEBUGGER_SETTINGS
4243

4344
# Set up my own color scheme with some additional definitions.
4445
color_scheme = TERMINAL_COLORS.copy()
46+
# color_scheme = {
47+
# Token: ('', ''),
48+
# Comment: ('gray', 'brightblack'),
49+
# Comment.Preproc: ('cyan', 'brightcyan'),
50+
# Keyword: ('blue', 'brightblue'),
51+
# Keyword.Type: ('cyan', 'brightcyan'),
52+
# Operator.Word: ('magenta', 'brightmagenta'),
53+
# Name.Builtin: ('cyan', 'brightcyan'),
54+
# Name.Function: ('green', 'brightgreen'),
55+
# Name.Namespace: ('_cyan_', '_brightcyan_'),
56+
# Name.Class: ('_green_', '_brightgreen_'),
57+
# Name.Exception: ('cyan', 'brightcyan'),
58+
# Name.Decorator: ('brightblack', 'gray'),
59+
# Name.Variable: ('red', 'brightred'),
60+
# Name.Constant: ('red', 'brightred'),
61+
# Name.Attribute: ('cyan', 'brightcyan'),
62+
# Name.Tag: ('brightblue', 'brightblue'),
63+
# String: ('gray', 'yellow'),
64+
# Number: ('blue', 'brightblue'),
65+
# Generic.Deleted: ('brightred', 'brightred'),
66+
# Generic.Inserted: ('green', 'brightgreen'),
67+
# Generic.Heading: ('**', '**'),
68+
# Generic.Subheading: ('*magenta*', '*brightmagenta*'),
69+
# Generic.Prompt: ('**', '**'),
70+
# Generic.Error: ('brightred', 'brightred'),
71+
# }
72+
73+
74+
4575
color_scheme[Generic.Strong] = ("*black*", "*white*")
4676
color_scheme[Name.Variable] = ("_black_", "_white_")
4777

4878
color_scheme[Generic.Strong] = ("*black*", "*white*")
4979
color_scheme[Name.Variable] = ("_black_", "_white_")
50-
color_scheme[Generic.Emph] = color_scheme[Comment.Preproc]
80+
color_scheme[Generic.Emph] = ("blue", "brightcyan")
5181

5282
# Assume pygments has fixed up the horrible atom colors
5383
# FIXME: change some horrible colors under atom dark
@@ -65,11 +95,10 @@
6595
def format_token(ttype, token, colorscheme=color_scheme, highlight="light"):
6696
if "plain" == highlight:
6797
return token
68-
dark_bg = "dark" == highlight
69-
98+
is_dark_bg = 1 if DEBUGGER_SETTINGS["highlight"] == "dark" else 0
7099
color = colorscheme.get(ttype)
71100
if color:
72-
color = color[dark_bg]
101+
color = color[is_dark_bg]
73102
if isinstance(token, tuple):
74103
# have (token, start offset)
75104
token = token[0]
@@ -166,9 +195,7 @@ class RSTTerminalFormatter(Formatter):
166195

167196
def __init__(self, **options):
168197
Formatter.__init__(self, **options)
169-
self.darkbg = (
170-
get_choice_opt(options, "bg", ["light", "dark"], "light") != "dark"
171-
)
198+
self.is_dark_bg = 1 if DEBUGGER_SETTINGS["highlight"] == "dark" else 0
172199
self.colorscheme = options.get("colorscheme", None) or color_scheme
173200
self.width = options.get("width", 80)
174201
self.verbatim = False
@@ -203,7 +230,7 @@ def write_verbatim(self, text):
203230
# color
204231
if self.__class__ != MonoRSTTerminalFormatter:
205232
cs = self.colorscheme.get(Verbatim)
206-
color = cs[self.darkbg]
233+
color = cs[self.is_dark_bg]
207234
else:
208235
color = None
209236
pass
@@ -226,7 +253,7 @@ def reflow_text(self, text, ttype, color):
226253
# print '%r' % text
227254
# from trepan.api import debug
228255
# if u' or ' == text: debug()
229-
if text == "::" and ttype == Token.Literal.String.Escape:
256+
if text == "::" and ttype == Token.Literal.String:
230257
self.verbatim = "colon-verbatim"
231258
return
232259
elif (
@@ -318,7 +345,7 @@ def format_unencoded(self, tokensource, outfile):
318345
color = self.colorscheme.get(resolved_type)
319346
pass
320347
if color:
321-
color = color[self.darkbg]
348+
color = color[self.is_dark_bg]
322349
self.reflow_text(text, ttype, color)
323350
pass
324351
return

trepan/processor/command/disassemble.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009, 2012-2018, 2020, 2023 Rocky Bernstein
3+
# Copyright (C) 2009, 2012-2018, 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
@@ -89,6 +89,11 @@ class DisassembleCommand(DebuggerCommand):
8989
With a class, method, function, pyc-file, code or string argument
9090
disassemble that.
9191
92+
Assembly output format is be controlled by the setting of `set
93+
asmfmt`. Output formats are those described the `xdis` `pydisasm`
94+
disassembler.
95+
96+
9297
Examples:
9398
--------
9499
::
@@ -105,7 +110,9 @@ class DisassembleCommand(DebuggerCommand):
105110
See also:
106111
---------
107112
108-
`help syntax arange`, `deparse`, `list`, `info pc`."""
113+
`help syntax arange`, `deparse`, `list`, `info pc`, `set asmfmt`.
114+
115+
"""
109116

110117
aliases = ("disasm",) # Note: we will have disable
111118
short_help = "Disassemble Python bytecode"

0 commit comments

Comments
 (0)