Skip to content

Commit

Permalink
Strip escape sequences from file
Browse files Browse the repository at this point in the history
From #2
  • Loading branch information
4iar committed Aug 10, 2021
1 parent ae52495 commit 6c96b91
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion write.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import lldb
import argparse
import re


def parse_args(raw_args):
Expand All @@ -27,11 +28,17 @@ def parse_args(raw_args):
return args


def strip_esc_seq(s):
"""Strip ANSI escape sequences from string."""
esc_seq_re = re.compile(r'\x1b[^m]*m')
return esc_seq_re.sub('', s)


def write_to_file(filename, command, output):
"""Write the output to the given file, headed by the command"""
with open(filename, 'w') as f:
f.write("(lldb) " + command + '\n\n')
f.write(output)
f.write(strip_esc_seq(output))


def handle_call(debugger, raw_args, result, internal_dict):
Expand Down

0 comments on commit 6c96b91

Please sign in to comment.