Skip to content

Commit

Permalink
Update write.py
Browse files Browse the repository at this point in the history
Adding recommendation from 4iar#2
  • Loading branch information
egachi authored Jul 28, 2021
1 parent 51b948c commit 1d0a5fc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion write.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function
import lldb
import argparse
import re


def parse_args(raw_args):
Expand All @@ -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):
Expand Down

0 comments on commit 1d0a5fc

Please sign in to comment.