Skip to content

Commit

Permalink
Convert red to python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
stroxler committed Jul 20, 2023
1 parent 71f8618 commit d1961b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self, execute, prompt, ctx):
<dim>(time travel)</dim> """))

time = prompt(banner)
if not len(time):
if not time:
return

now = int(ctx['loc'].get('time') or 0)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions red.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


debugger_log = open('/tmp/red.log', 'w')

def trace(text):
debugger_log.write(text)
debugger_log.flush()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion vt100.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d1961b2

Please sign in to comment.