From d1961b244ae2f94cc2c5df82cbaabf80642f838b Mon Sep 17 00:00:00 2001 From: Steven Troxler Date: Thu, 20 Jul 2023 10:01:33 -0700 Subject: [PATCH] Convert red to python 3 --- commands.py | 6 +++--- red.py | 10 ++++++---- vt100.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/commands.py b/commands.py index 72eccba..877723b 100644 --- a/commands.py +++ b/commands.py @@ -79,7 +79,7 @@ def run(self, execute, prompt, ctx): (time travel) """)) time = prompt(banner) - if not len(time): + if not time: return now = int(ctx['loc'].get('time') or 0) @@ -125,7 +125,7 @@ class Print(Command): def run(self, execute, prompt, ctx): var = prompt(vt100.magenta(vt100.dim('(print) '))) - if not len(var): + if not var: return output = execute('print ' + var) return vt100.magenta(output) @@ -198,7 +198,7 @@ class Custom(Command): def run(self, execute, prompt, ctx): command = prompt(vt100.dim('(odb) ')) - if not len(command): + if not command: return output = execute(command) return vt100.blue('>> {0}\n'.format(command)) + output diff --git a/red.py b/red.py index 0acdd18..d31691c 100755 --- a/red.py +++ b/red.py @@ -14,6 +14,7 @@ debugger_log = open('/tmp/red.log', 'w') + def trace(text): debugger_log.write(text) debugger_log.flush() @@ -116,7 +117,7 @@ def hl(src, breakpoint_lines): text = re.sub(a_ptrn, vt100.bold('\\1'), text) text = re.sub(b_ptrn, vt100.bold('\\1'), text) - symbol = u'\u2022' if has_breakpoint else ' ' + symbol = '\u2022' if has_breakpoint else ' ' # Can't use red twice, the closing color tag will mess the outputs if not is_current: @@ -170,9 +171,10 @@ def main(args): return 1 dbgr = subprocess.Popen(['ocamldebug', '-emacs'] + command_line, + encoding='utf-8', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - print(debugger_command(dbgr, '')[0].replace('\tOCaml Debugger version ', vt100.red(u'\u2022 RED') + ' OCamlDebug v')) + print(debugger_command(dbgr, '')[0].replace('\tOCaml Debugger version ', vt100.red('\u2022 RED') + ' OCamlDebug v')) print(vt100.dim('Press ? for help')) print(debugger_command(dbgr, 'start')[0]) @@ -215,9 +217,9 @@ def prompt(text): file_name = loc.get('file') listing = hl(execute('list'), breakpoint_lines_for_file(breakpoints, file_name)) if listing: - console.print_text((u'\u2500[ %s ]' % loc.get('file')) + u'\u2500' * 300) + console.print_text(('\u2500[ %s ]' % loc.get('file')) + '\u2500' * 300) console.print_text(listing) - console.print_text(u'\u2500' * 300) + console.print_text('\u2500' * 300) else: module = loc.get('module') if module: diff --git a/vt100.py b/vt100.py index c4a5ac0..a13499b 100644 --- a/vt100.py +++ b/vt100.py @@ -72,7 +72,7 @@ def print_text(self, text): def safe_input(self, prompt=None): self.lines_printed += 1 try: - return raw_input(prompt) + return input(prompt) except: pass