Skip to content

Commit 2e08659

Browse files
committed
Improve pyasm listing...
fix bug in going into Python when terminal handling does not allow.
1 parent 92d9466 commit 2e08659

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

trepan/processor/command/list.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def run(self, args):
152152
"output": self.settings["highlight"],
153153
"strip_nl": False,
154154
}
155+
style = self.settings.get("style", "plain")
156+
is_plain = style in ("plain", "none")
155157

156158
for field in ("highlight", "style"):
157159
if field in self.settings:
@@ -161,17 +163,28 @@ def run(self, args):
161163
if is_pyasm:
162164
lineno = first
163165
opts["strip_nl"] = True
166+
opts["style"] = "plain"
164167

165168
# FIXME add approximate
166-
line, pyasm_line_index = pyficache.get_pyasm_line(filename, lineno, is_source_line=True, opts=opts)
169+
line, pyasm_line_index = pyficache.get_pyasm_line(
170+
filename, lineno, is_source_line=True, opts=opts
171+
)
167172
proc.list_lineno = lineno
168173
if line is None:
169174
self.errmsg(f"cannot find assembly for line number {lineno}")
170175
return
171176
while lineno <= last:
177+
if not is_plain:
178+
line = pyficache.highlight_string(
179+
line, lexer=pyficache.pyasm_lexer, style=style
180+
)
181+
if line.endswith("\n"):
182+
line = line[:-1]
172183
self.msg(line)
173184
pyasm_line_index += 1
174-
line, pyasm_line_index = pyficache.get_pyasm_line(filename, pyasm_line_index, is_source_line=False, opts=opts)
185+
line, pyasm_line_index = pyficache.get_pyasm_line(
186+
filename, pyasm_line_index, is_source_line=False, opts=opts
187+
)
175188
if line is None:
176189
break
177190
else:
@@ -246,7 +259,7 @@ def doit(cmd, args):
246259
# doit(lcmd, ['list', "python3-trepan/test/example/00_chained-compare-cpython-314.pyasm:3"])
247260

248261
# Note: osp is defined above
249-
doit(lcmd, ['list', "osp:1"])
262+
doit(lcmd, ["list", "osp:1"])
250263
# print('--' * 10)
251264

252265
print("--" * 10)

trepan/processor/command/python.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ def console_runcode(code_obj):
199199
if use_pyrepl:
200200
if not pyrepl_console:
201201
pyrepl_console = InteractiveColoredConsole(my_locals, filename="<trepan>")
202-
203202
pyrepl_console.runcode = console_runcode
204203
setattr(pyrepl_console, "globals", my_globals)
205204
if readfunc is not None:
@@ -213,9 +212,9 @@ def console_runcode(code_obj):
213212
errmsg_func(
214213
"Colored PyREPL can't be used here; using standard Python shell"
215214
)
216-
217-
msg_func(banner)
218-
run_multiline_interactive_console(pyrepl_console)
215+
else:
216+
msg_func(banner)
217+
run_multiline_interactive_console(pyrepl_console)
219218

220219
# Fancy color pyrepl console can't be used, so use InteractiveConsole.
221220
if not pyrepl_console:

trepan/processor/print.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
307307
if remapped_line_number >= 0:
308308
# FIXME: +1 is because getlines is 0 origin.
309309
remapped_line_number += 1
310+
if line is not None and opts["style"] not in ("plain", "none"):
311+
line = pyficache.highlight_string(
312+
line, lexer=pyficache.pyasm_lexer, style=opts["style"]
313+
)
314+
if line.endswith("\n"):
315+
line = line[:-1]
316+
310317
else:
311318
remapped_line_number = -1 # -1 means no remapping
312319
line = pyficache.getline(filename, line_number, opts)

0 commit comments

Comments
 (0)