From 1d0a5fc82f573c8722da781fe9c1946e6db0ad20 Mon Sep 17 00:00:00 2001 From: Edison Garcia Date: Tue, 27 Jul 2021 19:55:45 -0500 Subject: [PATCH] Update write.py Adding recommendation from https://github.com/4iar/lldb-write/issues/2 --- write.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/write.py b/write.py index b8e5203..e7769ba 100755 --- a/write.py +++ b/write.py @@ -3,6 +3,7 @@ from __future__ import print_function import lldb import argparse +import re def parse_args(raw_args): @@ -28,13 +29,21 @@ 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""" mode = 'a' if os.path.exists(filename) else 'w' f = open(filename, mode) f.write("(lldb) " + command + '\n\n') - f.write(output) + f.write(strip_esc_seq(output)) + f.flush(); + f.close(); def handle_call(debugger, raw_args, result, internal_dict):