Skip to content

Commit

Permalink
logging: use re_vt100 helper
Browse files Browse the repository at this point in the history
Use the centrally compiled helper and remove the class property
indirection.

Signed-off-by: Rouven Czerwinski <[email protected]>
  • Loading branch information
Emantor committed Apr 28, 2023
1 parent 4d681c9 commit a04e3e1
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions labgrid/logging.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
import logging

import attr

from .step import steps, StepEvent
from .util import re_vt100

DEFAULT_FORMAT = "%(levelname)-7.7s %(name)15.15s: %(message)s"

Expand Down Expand Up @@ -63,15 +63,12 @@ class SerialLoggingReporter:
default=None,
validator=attr.validators.optional(attr.validators.instance_of(StepEvent)),
)
re_vt100 = attr.ib(
default=re.compile(r"(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]")
)

def __attrs_post_init__(self):
steps.subscribe(self.notify)

def vt100_replace_cr_nl(self, buf):
string = self.re_vt100.sub("", buf.decode("utf-8", errors="replace"))
string = re_vt100.sub("", buf.decode("utf-8", errors="replace"))
string = string.replace("\r", "␍")
string = string.replace("\n", "␤")
string = string.replace("\b", "␈")
Expand Down

0 comments on commit a04e3e1

Please sign in to comment.