Skip to content

Commit

Permalink
Merge pull request #332 from carlmontanari/feat/more-ansi-pattern-exp…
Browse files Browse the repository at this point in the history
…ansion

feat: further expanded asni pattern stuff
  • Loading branch information
carlmontanari authored May 29, 2024
2 parents 161beef + bda36bb commit a9cadea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scrapli/channel/base_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
from scrapli.transport.base import AsyncTransport, Transport

ANSI_ESCAPE_PATTERN = re.compile(
pattern=rb"[\x1B\x9B\x9D](\s)?" # Prefix ESC (^) or CSI (^[) or OSC (^])
pattern=rb"[\x1B\x9B\x9D](\s)?" # Prefix ESC (^) or CSI (^[) or OSC (^)
rb"("
rb"([78ME])" # control cursor position
rb"|"
rb"((\]\d).*[\x07])" # BEL (Terminal bell)
rb"((\]\d).*?[\x07])" # BEL (Terminal bell)
rb"|"
rb"(\[[{}();#=?0-9]*[A-Zhglnmsu~])" # control codes starts with `[` e.x. ESC [2;37;41m
rb"(\[.*?[@-~])" # control codes starts with `[` e.x. ESC [2;37;41m
rb"|"
rb"(\[.*?[0-9;]m)" # Select Graphic Rendition (SGR) control sequence
rb")",
flags=re.VERBOSE,
)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/channel/test_base_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ def test_process_output(base_channel):
b"\x1b[?2004h\x1b]0;user@line5-cpe-0: ~\x07user@line5-cpe-0:~$",
b"user@line5-cpe-0:~$",
),
# https://github.com/carlmontanari/scrapli/issues/331
(
b"\x1b[?6l\x1b[1;80r\x1b[?7h\x1b[2J\x1b[1;1H\x1b[1920;1920H\x1b[6n\x1b[1;1HYour previous successful login (as manager) was on 2024-05-24 11:29:02 \n from X.X.X.X\n\x1b[1;80r\x1b[80;1H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[80;1HHOSTNAME# \x1b[80;1H\x1b[80;20H\x1b[80;1H\x1b[?25h\x1b[80;20H\x1b[1;0H\x1b[1M\x1b[80;1H\x1b[1L\x1b[80;20H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[1;80r\x1b[80;1H\x1b[1;80r\x1b[80;1H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[80;1HHOSTNAME# \x1b[80;1H\x1b[80;20H\x1b[80;1H\x1b[?25h\x1b[80;20H",
b"Your previous successful login (as manager) was on 2024-05-24 11:29:02 \n from X.X.X.X\nHOSTNAME# HOSTNAME# ",
),
),
)
def test_strip_ansi(base_channel, buf: bytes, expected: bytes):
Expand Down

0 comments on commit a9cadea

Please sign in to comment.