Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text widget that understands ANSI color escape sequences

47 views
Skip to first unread message

Why Tea

unread,
May 31, 2007, 8:30:58 PM5/31/07
to
Is there a text widget that understands ANSI color escape sequences?
I'd like to have it as a log file viewer that shows text in colors
according to the escape sequences. Any suggestion will be greatly
appreciated.

/Why Tea

sleb...@gmail.com

unread,
May 31, 2007, 10:05:18 PM5/31/07
to

Alexandre Ferrieux

unread,
Jun 1, 2007, 1:44:28 AM6/1/07
to
On Jun 1, 4:05 am, "slebet...@yahoo.com" <slebet...@gmail.com> wrote:
>
> http://wiki.tcl.tk/1143

Looking at this, I'm a bit surprised by the [lsearch]:

proc + {args} {
variable map
set t 0
foreach i $args {
set ix [lsearch -exact $map $i]
if {$ix>-1} {lappend t [lindex $map [incr ix]]}
}
return "\033\[[join $t {;}]m"
}

Why not use an array there ?

array set map {bold 1 ...}
proc + {args} {
variable map
set t 0
foreach i $args {
if {[info exists map($i)]} {lappend t $map($i)}
}
return "\033\[[join $t {;}]m"
}

-Alex

suchenwi

unread,
Jun 1, 2007, 5:25:31 AM6/1/07
to

Alexandre Ferrieux schrieb:

> Why not use an array there ?

Sure. That code is quite old, I may have been under the impression of
the fact that arrays take 42 bytes overhead per elements, while lists
need only 12. But as the map isn't extremely big, an array is ok here
- and even a local one, in order to avoid one global variable :)

sleb...@gmail.com

unread,
Jun 1, 2007, 1:39:23 PM6/1/07
to
On Jun 1, 5:25 pm, suchenwi <richard.suchenwirth-

Yeah, the code is from 2001. Back then even I haven't even heard of
arrays. I've only started using arrays in 2004 ;-) I'm not sure when
arrays were introduced but back then not many people were using it yet.

sleb...@gmail.com

unread,
Jun 1, 2007, 1:42:46 PM6/1/07
to
On Jun 1, 5:25 pm, suchenwi <richard.suchenwirth-
bauersa...@siemens.com> wrote:

Heh, I just realised. Doubtless that sometime in 2010 someone will ask
the same question about why one would write:

foreach {x y} $xy break

instead of

lassign $xy x y

(and people will inevitably still complain that Tcl doesn't evolve)

David Gravereaux

unread,
Jun 1, 2007, 3:03:50 PM6/1/07
to

Not a text widget, but I wrote an ANSI decoder for window's consoles a ways back:
http://www.pobox.com/~davygrvy/tclstuff/winAnsiCon12_pack.zip

I had the intent to put it in the windows console channel driver, but opted not to
as the interface wouldn't have been "comfortable" for programmers.

--
If you want to stay dad you've got to polish your image. I think the image
we need to create for you is "repentant but learning". -- Calvin

signature.asc

Eric Hassold

unread,
Jun 1, 2007, 5:34:18 PM6/1/07
to
sleb...@yahoo.com wrote :

Are you sure about the "not many people using it in 2001" ?? Don't know
either when array was introduced exactly, but I know for sure it was
there in 7.0 (released in 1995), and nearly all current sub-commands of
array were there in 7.4 (june 1995). Hope new features like "lassign",
"dict", etc... won't need 6 or 12 more years before people hear about
them ;-)

I'm pretty sure Richard was mastering arrays much before 2001 (and even
knew the 42 bytes overhead per entry in hash vs 12 for list!)

Eric

Alexandre Ferrieux

unread,
Jun 1, 2007, 6:32:22 PM6/1/07
to
On Jun 1, 11:25 am, suchenwi <richard.suchenwirth-

bauersa...@siemens.com> wrote:
> Alexandre Ferrieux schrieb:
>
> > Why not use an array there ?
>
> Sure. That code is quite old, I may have been under the impression of
> the fact that arrays take 42 bytes overhead per elements, while lists
> need only 12. But as the map isn't extremely big, an array is ok here

Well, a memory footprint per element means nothing since there are
just a constant number of them, while the lookup will occur for each
and every color command, hence the [lsearch] CPU overhead will hit
every line of (colorized) output.

> - and even a local one, in order to avoid one global variable :)

You still need a (namespace) global to avoid deserializing the array
at each call with [array set].

-Alex

Why Tea

unread,
Jun 2, 2007, 10:32:58 PM6/2/07
to

Thanks to everyone who replied. The solution provided in
http://wiki.tcl.tk/1143 looks like something I need. Will
explore more on that.

/Why Tea

0 new messages