Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added stripping of ANSI escape sequences (include colorization) from inputs #1038

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion monitor/filter_exception_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Esp32ExceptionDecoder(DeviceMonitorFilterBase):

BACKTRACE_PATTERN = re.compile(r"^Backtrace:(((\s?0x[0-9a-fA-F]{8}:0x[0-9a-fA-F]{8}))+)")
BACKTRACE_ADDRESS_PATTERN = re.compile(r'0x[0-9a-fA-F]{8}:0x[0-9a-fA-F]{8}')
ANSI_ESCAPE_PATTERN = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]')

def __call__(self):
self.buffer = ""
Expand All @@ -51,6 +52,11 @@ def __call__(self):
"""
)

if self.config.get("env:" + self.environment, "monitor_raw") == "yes":
sys.stderr.write(
"%s: The filter is disabled and will not be called, due to 'monitor_raw' = 'yes'.\n" % self.__class__.__name__
)

return self

def setup_paths(self):
Expand Down Expand Up @@ -100,7 +106,9 @@ def rx(self, text):
self.buffer = ""
last = idx + 1

m = self.BACKTRACE_PATTERN.match(line)
strip_line = self.strip_ansi(line)

m = self.BACKTRACE_PATTERN.match(strip_line)
if m is None:
continue

Expand Down Expand Up @@ -140,3 +148,6 @@ def strip_project_dir(self, trace):
break
trace = trace[:idx] + trace[idx + len(self.project_dir) + 1 :]
return trace

def strip_ansi(self, line):
return self.ANSI_ESCAPE_PATTERN.sub('', line)