[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Translate or remove escape codes from stream
From: |
Thomas Dickey |
Subject: |
Re: Translate or remove escape codes from stream |
Date: |
Mon, 6 Jun 2011 18:24:29 -0400 (EDT) |
On Mon, 6 Jun 2011, Jeff Barnes wrote:
A couple of weeks ago, the Bug-ncurses list provided very helpful tips for
capturing the stderr output from a library and printw'ing it to a WINDOW *.
Some of what I'm getting in the WINDOW * includes stuff like the following:
0:00:10.491677352 ^[[333m18212^[[00m 0x80efa30 ^[[32;01mINFO ^[[00m ^[[00;01;37;41m
GST_ELEMENT_FACTORY gstelementfactory.c:403:gst_element_factory_create:^[[00m creating
element "pipeline"
0:00:10.494354913 ^[[333m18212^[[00m 0x80efa30 ^[[32;01mINFO ^[[00m ^[[00;01;36m
GST_PLUGIN_LOADING gstplugin.c:660:gst_plugin_load_file:^[[00m plugin
"/opt/fsmd/lib/gstreamer-0.10/libgstneonhttpsrc.so" loaded
....
Ewwwwww
From gst-launch, the output looks great! Nice colors. No escape codes. But from
my program, well, I'd like to have human readable text. What would be really
great is if there were a quick and easy fix to translate the escape codes to
their ncurses attributes counterparts. But I'd bet that the escape codes are
different from terminal to terminal and the GST_DEBUG output uses terminfo and
such to figure out what the escape codes are.
If I can't translate the escape codes in a strait-forward way, the second best
option would be to just remove them from the string that goes to the window.
Anybody know of code examples to do either?
Most of the strings (at least, most of the ones you'll see) are
ANSI-formatted. Something like
\033\[[0-9;]*[:alpha:]]
There also could be escapes from "col", which are
\033[0-9]
Also, you can get backspaces. In vile's utility program "vile-manfilt",
I handled that sort of thing (though it in turn emits markup for vile,
to color things).
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net