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

Using less command in Tcl

163 views
Skip to first unread message

Jay

unread,
Jul 13, 2018, 3:38:01 PM7/13/18
to
I would like to view notes within a Tcl script using the less command and ANSI colors. This small example seems to work, but is there a preferred way? Is it a bad idea to use the less command while the Tcl script is still running behind it? Running this on macOS Sierra.

set str "\033\[97m RUSH \033\[96m2112"

exec /usr/bin/tput smcup >/dev/tty
exec echo $str | /usr/bin/less -R >/dev/tty
exec /usr/bin/tput rmcup >/dev/tty
put done

Jay

unread,
Jul 13, 2018, 3:49:25 PM7/13/18
to
Guess I don't really need tput in there:

set str "\033\[97m RUSH \033\[96m2112"
exec echo $str | /usr/bin/less -R >/dev/tty
puts done

Rich

unread,
Jul 13, 2018, 4:30:38 PM7/13/18
to
Jay <jy...@hotmail.com> wrote:
> I would like to view notes within a Tcl script using the less command
> and ANSI colors. This small example seems to work, but is there a
> preferred way?

Unless you want to start trying to interpret ANSI escape codes, this
seems a good way to view the color text.

It is, however, limited to only environments where 'less' is installed
and a color capable terminal is available.

> Is it a bad idea to use the less command while the Tcl script is
> still running behind it?

Since you did not put less into the background via your exec call, the
tcl script is not "running behind it". The Tcl script is paused,
waiting for the less command to terminate. Only once the command
terminates will the Tcl script start running again.

Jay

unread,
Jul 13, 2018, 4:59:50 PM7/13/18
to
Thank you Rich! Really appreciate your detail on this.

heinrichmartin

unread,
Jul 16, 2018, 3:20:27 AM7/16/18
to
On Friday, July 13, 2018 at 9:38:01 PM UTC+2, Jay wrote:
> I would like to view notes within a Tcl script using the less command and ANSI colors.

The keyword ANSI colors reminds me of the nice little ansifilter project by André Simon: http://andre-simon.de/doku/ansifilter/en/ansifilter.php

It is not your exact use case, but it could help to
* strip ANSI color codes from text or
* generate other formats (e.g. HTML if your App features a browser anyway, or LaTeX if you want to generate PDF reports, ...).

It has three modes: GUI, command line, Tcl; I am not using the GUI.

The Tcl package allows something like this:
expect:~$ package require ansifilter
0.1
expect:~$ ansifilter::tex_escape "\033\[97m RUSH \033\[96m2112"
{\color[rgb]{1,1,1}~RUSH~}{\color[rgb]{0,1,1}2112\hspace*{\fill}\\
}
expect:~$

Maybe that helps anyone :-)
Martin

Disclaimer: I contributed the (unfinished) Tcl mode, https://gitlab.com/saalen/ansifilter/tree/master/src/tcl

Jay

unread,
Jul 16, 2018, 11:23:25 AM7/16/18
to
> The keyword ANSI colors reminds me of the nice little ansifilter project by André Simon: http://andre-simon.de/doku/ansifilter/en/ansifilter.php
>
> It is not your exact use case, but it could help to
> * strip ANSI color codes from text or
> * generate other formats (e.g. HTML if your App features a browser anyway, or LaTeX if you want to generate PDF reports, ...).
>
> It has three modes: GUI, command line, Tcl; I am not using the GUI.
>
> The Tcl package allows something like this:
> expect:~$ package require ansifilter
> 0.1
> expect:~$ ansifilter::tex_escape "\033\[97m RUSH \033\[96m2112"
> {\color[rgb]{1,1,1}~RUSH~}{\color[rgb]{0,1,1}2112\hspace*{\fill}\\
> }
> expect:~$
>
> Maybe that helps anyone :-)
> Martin
>
> Disclaimer: I contributed the (unfinished) Tcl mode, https://gitlab.com/saalen/ansifilter/tree/master/src/tcl

Thank you Martin. I will take a look at this, and thank you for the example code.
0 new messages