From 6c96b91fd442958bb6088f2da58e4643b9de883e Mon Sep 17 00:00:00 2001 From: 4iar Date: Tue, 10 Aug 2021 07:46:29 +0100 Subject: [PATCH] Strip escape sequences from file From #2 --- write.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/write.py b/write.py index f39e896..81dd817 100755 --- a/write.py +++ b/write.py @@ -1,6 +1,7 @@ from __future__ import print_function import lldb import argparse +import re def parse_args(raw_args): @@ -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):