fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

Does not strip all ANSI sequences correctly #50

Closed SteveAyre closed 2 years ago

SteveAyre commented 5 years ago

The current code does not handle some ANSI sequences cleanly, for example ones that modify cursor position.

For example: '\x1b[1;13r\x1b[1;1H\x1b[24;1HPress any key to continue\x1b[13;1H\x1b[?25h\x1b[24;27H\x1b[?6l\x1b[1;24r\x1b[?7l\x1b[2J\x1b[1;1H\x1b[1920;1920H\x1b[6n\x1b[1;1H'

is stripped to: 'rHHPress any key to continueH?25hH?6lr?7lH20;1920HnH'

fruch commented 5 years ago

Hi Steve, thanks for submitting this issue.

I haven't touched this code in a while since I'm not using it anymore.

you want to try and open a PR ? I'll do my best to help.

leonardopsantos commented 3 years ago

I'm monkey-patching a function with a different regex:

import paramiko_expect

def strip_ansi_codes(s):
    return re.sub(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])', '', s)

paramiko_expect.strip_ansi_codes = strip_ansi_codes
fruch commented 2 years ago

79 fixes this