#[para]We want to resolve the index used, without passing arbitrary expressions into the 'expr' function - which could have security risks.
#[para]lindex_resolve will parse the index expression and return -1 if the supplied index expression is out of bounds for the supplied list.
#[para]Otherwise it will return an integer corresponding to the position in the list.
#[para]Like Tcl list commands - it will produce an error if the form of the
#[para]Like Tcl list commands - it will produce an error if the form of the index is not acceptable
#Note that for an index such as $x+1 - we never see the '$x' as it is substituted in the calling command. We will get something like 10+1 - which we will resolve (hopefully safely) with expr
set parts [punk::ansi::ta::split_codes_single $v] ;#caller may have supplied separated codes eg "[a+ Yellow][a+ red]"
set ansi_codes [list] ;
foreach {pt code} $parts {
if {$pt ne ""} {
#we don't expect plaintext in an ansibase
error "Unable to interpret $k value as ansi SGR codes. Plaintext detected. Consider using for example: '\[punk::ansi::a+ green]' (or alias '\[a+ green]') to build ansi. debug view: [punk::ansi::ansistring VIEW $v]"
}
if {$code ne ""} {
lappend ansi_codes $code
}
}
set ansival [punk::ansi::codetype::sgr_merge $ansi_codes]
lappend checked_opts $k $ansival
}
-ansireset {
if {$v eq "\uFFEF"} {
lappend checked_opts $k "\x1b\[m" ;# [a]
@ -607,56 +673,35 @@ namespace eval textblock {
left {
set header_boxlimits {hl tlc blc vll}
set header_joins [list down-$ftype_body]
set boxlimits_build {hlb blc vll}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll}
set boxlimits_headerless {hlb hlt blc vll tlc}
set joins {down}
}
inner {
set header_boxlimits {hl tlc blc vll}
set header_joins [list left down-$ftype_body]
set boxlimits_build {hlb blc vll}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll}
set boxlimits_headerless {hlb hlt blc vll tlc}
set joins {down left}
}
right {
set header_boxlimits {hl tlc blc vl trc brc}
set header_boxlimits {hl tlc blc vll vlr trc brc}
set header_joins [list left down-$ftype_body]
set boxlimits_build {hlb blc vll vlr brc}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll vlr brc}
set boxlimits_headerless {hlb hlt blc vll vlr brc tlc trc}
set joins {down left}
}
solo {
set header_boxlimits {hl tlc blc vl trc brc}
set header_boxlimits {hl tlc blc vll vlr trc brc}
set header_joins [list down-$ftype_body]
set boxlimits_build {hlb blc vll vlr brc}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_headerless {hlb hlt blc vl brc tlc trc}
set boxlimits_position {hlb blc vll vlr brc}
set boxlimits_headerless {hlb hlt blc vll vlr brc tlc trc}
set joins {down}
}
}
#use struct::set instead of simple for loop - will be faster at least when critcl available
set boxlimits [struct::set intersect [dict get $o_opts_table -framelimits_body] $boxlimits_position]
error "unrecognised option '$k'. Known options [dict keys $defaults]"
}
@ -1132,10 +1153,10 @@ namespace eval textblock {
if {[dict get $opts -show_edge] eq "\uFFEF"} {
dict set opts -show_edge 1
}
if {[dict get $opts -show_separators] eq "\uFFEF"} {
dict set opts -show_separators 1
if {[dict get $opts -show_seps] eq "\uFFEF"} {
dict set opts -show_seps 1
}
set t [textblock::class::table new -show_header 0 -show_edge [dict get $opts -show_edge] -frametype [dict get $opts -frametype] -show_separators [dict get $opts -show_separators]]
set t [textblock::class::table new -show_header 0 -show_edge [dict get $opts -show_edge] -frametype [dict get $opts -frametype] -show_seps [dict get $opts -show_seps]]
for {set c 0} {$c < $cols} {incr c} {
$t add_column -header c$c
}
@ -2839,7 +2860,7 @@ namespace eval textblock {
#boxlimits used for partial borders in table generation
append warningblock \n "WARNING: textblock package couldn't be loaded. Side-by-side display not available"
} else {
set introblock [textblock::join " " $mascotblock " " $text]
set introblock [textblock::join " " \n$mascotblock " " $text]
}
lappend chunks [list stdout $introblock]
if {$topic in [list tcl]} {
if {[punk::repl::has_script_var_bug]} {
append warningblock \n "minor warning: punk::repl::has_script_var_bug returned true! (string rep for list variable in script generated when script changed)"
}
}
set text ""
if {$topic in [list env environment]} {
set known $::punk::config::known_punk_env_vars
append text $linesep\n
append text "punk environment vars:\n"
append text $linesep\n
set col1 [string repeat " " 25]
set col2 [string repeat " " 50]
foreach v $known {
set c1 [overtype::left $col1 $v]
if {[info exists ::env($v)]} {
set c2 [overtype::left $col2 [set ::env($v)]
} else {
set c2 [overtype::right $col2 "(NOT SET)"]
}
append text "$c1 $c2\n"
}
append text $linesep\n
lappend chunks [list stdout $text]
}
if {$topic in [list console terminal]} {
lappend cstring_tests [dict create\
type "PM "\
@ -7034,24 +7045,26 @@ namespace eval punk {
}
}
lappend chunks [list stdout $introblock]
lappend chunks [list stderr $warningblock]
if {$topic in [list topics help]} {
set text ""
set topics [dict create\
"topic|help" "List help topics"\
"topics|help" "List help topics"\
"tcl" "Tcl version warnings"\
"env|environment" "punkshell environment vars"\
"console|terminal" "Some console behaviour tests and warnings"\
set parts [punk::ansi::ta::split_codes_single $v] ;#caller may have supplied separated codes eg "[a+ Yellow][a+ red]"
set ansi_codes [list] ;
foreach {pt code} $parts {
if {$pt ne ""} {
#we don't expect plaintext in an ansibase
error "Unable to interpret $k value as ansi SGR codes. Plaintext detected. Consider using for example: '\[punk::ansi::a+ green]' (or alias '\[a+ green]') to build ansi. debug view: [punk::ansi::ansistring VIEW $v]"
}
if {$code ne ""} {
lappend ansi_codes $code
}
}
set ansival [punk::ansi::codetype::sgr_merge $ansi_codes]
lappend checked_opts $k $ansival
}
-ansireset {
if {$v eq "\uFFEF"} {
lappend checked_opts $k "\x1b\[m" ;# [a]
@ -607,56 +673,35 @@ namespace eval textblock {
left {
set header_boxlimits {hl tlc blc vll}
set header_joins [list down-$ftype_body]
set boxlimits_build {hlb blc vll}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll}
set boxlimits_headerless {hlb hlt blc vll tlc}
set joins {down}
}
inner {
set header_boxlimits {hl tlc blc vll}
set header_joins [list left down-$ftype_body]
set boxlimits_build {hlb blc vll}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll}
set boxlimits_headerless {hlb hlt blc vll tlc}
set joins {down left}
}
right {
set header_boxlimits {hl tlc blc vl trc brc}
set header_boxlimits {hl tlc blc vll vlr trc brc}
set header_joins [list left down-$ftype_body]
set boxlimits_build {hlb blc vll vlr brc}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_position {hlb blc vll vlr brc}
set boxlimits_headerless {hlb hlt blc vll vlr brc tlc trc}
set joins {down left}
}
solo {
set header_boxlimits {hl tlc blc vl trc brc}
set header_boxlimits {hl tlc blc vll vlr trc brc}
set header_joins [list down-$ftype_body]
set boxlimits_build {hlb blc vll vlr brc}
set boxlimits {}
foreach l $boxlimits_build {
if {$l in [dict get $o_opts_table -framelimits_body]} {
lappend boxlimits $l
}
}
set boxlimits_headerless {hlb hlt blc vl brc tlc trc}
set boxlimits_position {hlb blc vll vlr brc}
set boxlimits_headerless {hlb hlt blc vll vlr brc tlc trc}
set joins {down}
}
}
#use struct::set instead of simple for loop - will be faster at least when critcl available
set boxlimits [struct::set intersect [dict get $o_opts_table -framelimits_body] $boxlimits_position]
error "unrecognised option '$k'. Known options [dict keys $defaults]"
}
@ -1132,10 +1153,10 @@ namespace eval textblock {
if {[dict get $opts -show_edge] eq "\uFFEF"} {
dict set opts -show_edge 1
}
if {[dict get $opts -show_separators] eq "\uFFEF"} {
dict set opts -show_separators 1
if {[dict get $opts -show_seps] eq "\uFFEF"} {
dict set opts -show_seps 1
}
set t [textblock::class::table new -show_header 0 -show_edge [dict get $opts -show_edge] -frametype [dict get $opts -frametype] -show_separators [dict get $opts -show_separators]]
set t [textblock::class::table new -show_header 0 -show_edge [dict get $opts -show_edge] -frametype [dict get $opts -frametype] -show_seps [dict get $opts -show_seps]]