Wednesday, June 01, 2022

Tabulate

 Simple way of inserting beautified tables into the gnocl::text widget.



# !/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

## insert the list contents as in text widget as a formatted table
#
# @param    wid        text widget-id
# @param    lst        tcl list
# @param    id        table id
# @param    args    additional tag parameters
#
proc tabulate {wid lst {id 1} args} {

    if {$args == ""} { set args "-tabs 100" }

    foreach row $lst { append res [join $row \t]\n }

    $wid tag create _tab_table_$id {*}$args
    $wid insert end $res -tags _tab_table_$id

}

set txt [gnocl::text]
gnocl::window -child $txt -setSize 0.4

set lst(1) {{red orange yellow green blue indigo violet} {magenta cyan yellow brown grey black white}}
set lst(2) {{how now brown cow} {she sells sea shells by the sea shore}}
set lst(3) {{peter piper picked a peck of pickled peppers} {the peck of peppers peter piper picked}}

tabulate $txt $lst(1) 1 -tabs 120 -paragraph red -font {12}
tabulate $txt $lst(2) 2 -tabs 80 -foreground magenta
tabulate $txt $lst(3) 3 -tabs 80 -foreground white -paragraph #000000 -font {10}



No comments: