Attempting to parse free-form ANSI text.

Michael B. Trausch mike$#at^&nospam!%trauschus
Sun Oct 22 06:34:14 CEST 2006


Alright... I am attempting to find a way to parse ANSI text from a
telnet application.  However, I am experiencing a bit of trouble.

What I want to do is have all ANSI sequences _removed_ from the output,
save for those that manage color codes or text presentation (in short,
the ones that are ESC[#m (with additional #s separated by ; characters).
 The ones that are left, the ones that are the color codes, I want to
act on, and remove from the text stream, and display the text.

I am using wxPython's TextCtrl as output, so when I "get" an ANSI color
control sequence, I want to basically turn it into a call to wxWidgets'
TextCtrl.SetDefaultStyle method for the control, adding the appropriate
color/brightness/italic/bold/etc. settings to the TextCtrl until the
next ANSI code comes in to alter it.

It would *seem* easy, but I cannot seem to wrap my mind around the idea.
 :-/

I have a source tarball up at http://fd0man.theunixplace.com/Tmud.tar
which contains the code in question.  In short, the information is
coming in over a TCP/IP socket that is traditionally connected to with a
telnet client, so things can be broken mid-line (or even mid-control
sequence).  If anyone has any ideas as to what I am doing, expecting, or
assuming that is wrong, I would be delighted to hear it.  The code that
is not behaving as I would expect it to is in src/AnsiTextCtrl.py, but I
have included the entire project as it stands for completeness.

Any help would be appreciated!  Thanks!

	-- Mike



More information about the Python-list mailing list