VT100 in Python
Nick Craig-Wood
nick at craig-wood.com
Mon Sep 14 05:29:57 EDT 2009
Wolfgang Rohdewald <wolfgang at rohdewald.de> wrote:
> On Sunday 13 September 2009, Nadav Chernin wrote:
> > I'm writing program that read data from some instrument trough
> > RS232. This instrument send data in VT100 format. I need only to
> > extract the text without all other characters that describe how to
> > represent data on the screen. Is there some library in python for
> > converting VT100 strings?
>
> that should be easy using regular expressions
At a basic level parsing VT100 is quite easy, so you can get rid of
the VT100 control. They start with ESC, have other characters in the
middle then end with a letter (upper or lowercase), so a regexp will
make short work of them. Something like r"\x1B[^A-Za-z]*[A-Za-z]"
You might need to parse the VT100 stream as VT100 builds up a screen
buffer though and the commands don't always come out in the order you
might expect.
I think twisted has VT100 emulator, but I couldn't find it in a brief
search just now.
You'll find various others (like this one) if you search some more
http://svn.python.org/projects/python/branches/string_methods/Demo/cwilib/vt100.py
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list