Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

Text widget that understands ANSI color escape sequences


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

On Jun 1, 8:30 am, Why Tea <ytl@gmail.com> wrote:

> 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.

http://wiki.tcl.tk/1143
On Jun 1, 4:05 am, "slebet@yahoo.com" <slebet@gmail.com> wrote:

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

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 :)
On Jun 1, 5:25 pm, 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
> - and even a local one, in order to avoid one global variable :)

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.
On Jun 1, 5:25 pm, 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
> - and even a local one, in order to avoid one global variable :)

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)

Why Tea wrote:
> 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

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
1K Download

slebet@yahoo.com wrote :

> On Jun 1, 5:25 pm, 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
>> - and even a local one, in order to avoid one global variable :)

> 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.

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

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

On Jun 1, 12:05 pm, "slebet@yahoo.com" <slebet@gmail.com> wrote:

> On Jun 1, 8:30 am, Why Tea <ytl@gmail.com> wrote:

> > 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.

> http://wiki.tcl.tk/1143

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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc