Browse Source

textblock::table layout and width fixes, ansi fixes

master
Julian Noble 6 months ago
parent
commit
114f99b336
  1. 21
      src/modules/punk-0.1.tm
  2. 42
      src/modules/punk/ansi-999999.0a1.0.tm
  3. 24
      src/modules/punk/lib-999999.0a1.0.tm
  4. 4
      src/modules/punk/repl-0.1.tm
  5. 1231
      src/modules/textblock-999999.0a1.0.tm

21
src/modules/punk-0.1.tm

@ -6981,6 +6981,25 @@ namespace eval punk {
set text "" set text ""
if {$topic in [list env environment]} { if {$topic in [list env environment]} {
set known $::punk::config::known_punk_env_vars set known $::punk::config::known_punk_env_vars
append text \n
set usetable 1
if {$usetable} {
set t [textblock::class::table new -show_hseps 0 -show_header 1 -ansiborder_header [a+ web-green]]
foreach v $known {
if {[info exists ::env($v)]} {
set c2 [set ::env($v)]
} else {
set c2 "(NOT SET)"
}
$t add_row [list $v $c2]
}
$t configure_column 0 -headers [list "Punk environment vars"]
$t configure_column 0 -minwidth [expr {[$t column_datawidth 0]+4}] -blockalign left -textalign left -header_colspans {all}
append text [$t print]\n
$t destroy
} else {
append text $linesep\n append text $linesep\n
append text "punk environment vars:\n" append text "punk environment vars:\n"
append text $linesep\n append text $linesep\n
@ -6996,6 +7015,8 @@ namespace eval punk {
append text "$c1 $c2\n" append text "$c1 $c2\n"
} }
append text $linesep\n append text $linesep\n
}
lappend chunks [list stdout $text] lappend chunks [list stdout $text]
} }

42
src/modules/punk/ansi-999999.0a1.0.tm

@ -1495,7 +1495,9 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
lappend rows $row lappend rows $row
set row [list] set row [list]
} }
if {$i > 6} { if {$i == 8} {
set fg "web-white"
} elseif {$i > 6} {
set fg "web-black" set fg "web-black"
} }
#lappend row "[a+ {*}$fg Term-$cname][format %3s $i] $cname " #lappend row "[a+ {*}$fg Term-$cname][format %3s $i] $cname "
@ -1773,6 +1775,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
#$t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Rgb-$cdec] #$t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Rgb-$cdec]
$t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Web-$cname] $t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Web-$cname]
} }
$t configure -frametype {}
$t configure_column 0 -headers [list "[string totitle $g] colours"] $t configure_column 0 -headers [list "[string totitle $g] colours"]
$t configure_column 0 -header_colspans [list all] $t configure_column 0 -header_colspans [list all]
$t configure -ansibase_header [a+ web-black Web-white] $t configure -ansibase_header [a+ web-black Web-white]
@ -1787,9 +1790,21 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
$displaytable destroy $displaytable destroy
return $result return $result
} }
proc colourtable_x11diff {} { proc colourtable_x11diff {args} {
variable X11_colour_map_diff variable X11_colour_map_diff
variable WEB_colour_map variable WEB_colour_map
set defaults [dict create\
-return "string"\
]
dict for {k v} $args {
switch -- $k {
-return {}
default {
error "colourtable_x11diff unrecognised option '$k'. Known options [dict keys $defaults]"
}
}
}
set opts [dict merge $defaults $args]
set comparetables [list] ;# 2 side by side x11 and web set comparetables [list] ;# 2 side by side x11 and web
@ -1801,6 +1816,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
set fg "web-white" set fg "web-white"
$t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg X11-$cname] $t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg X11-$cname]
} }
$t configure -frametype block
$t configure_column 0 -headers [list "X11"] $t configure_column 0 -headers [list "X11"]
$t configure_column 0 -header_colspans [list all] $t configure_column 0 -header_colspans [list all]
$t configure -ansibase_header [a+ web-black Web-white] $t configure -ansibase_header [a+ web-black Web-white]
@ -1821,6 +1837,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
set fg "web-white" set fg "web-white"
$t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Web-$cname] $t configure_row [expr {[$t row_count]-1}] -ansibase [a+ $fg Web-$cname]
} }
$t configure -frametype block
$t configure_column 0 -headers [list "Web"] $t configure_column 0 -headers [list "Web"]
$t configure_column 0 -header_colspans [list all] $t configure_column 0 -header_colspans [list all]
$t configure -ansibase_header [a+ web-black Web-white] $t configure -ansibase_header [a+ web-black Web-white]
@ -1830,10 +1847,15 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
set displaytable [textblock::list_as_table 2 $comparetables -return object] set displaytable [textblock::list_as_table 2 $comparetables -return object]
$displaytable configure -show_header 0 -show_vseps 0 $displaytable configure -show_header 0 -show_vseps 0
if {[dict get $opts -return] eq "string"} {
set result [$displaytable print] set result [$displaytable print]
$displaytable destroy $displaytable destroy
return $result return $result
} }
return $displaytable
}
proc a? {args} { proc a? {args} {
#*** !doctools #*** !doctools
#[call [fun a?] [opt {ansicode...}]] #[call [fun a?] [opt {ansicode...}]]
@ -2141,9 +2163,10 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
#[para]punk::ansi::a Red #[para]punk::ansi::a Red
#[para]see [cmd punk::ansi::a?] to display a list of codes #[para]see [cmd punk::ansi::a?] to display a list of codes
#function name part of cache-key because a and a+ return slightly different results (a has leading reset)
variable sgr_cache variable sgr_cache
if {[dict exists $sgr_cache $args]} { if {[dict exists $sgr_cache a+$args]} {
return [dict get $sgr_cache $args] return [dict get $sgr_cache a+$args]
} }
#don't disable ansi here. #don't disable ansi here.
@ -2358,7 +2381,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
} else { } else {
set result "\x1b\[[join $t {;}]m" set result "\x1b\[[join $t {;}]m"
} }
dict set sgr_cache $args $result dict set sgr_cache a+$args $result
return $result return $result
} }
@ -2373,9 +2396,10 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
#[para]punk::ansi::a Red #[para]punk::ansi::a Red
#[para]see [cmd punk::ansi::a?] to display a list of codes #[para]see [cmd punk::ansi::a?] to display a list of codes
#It's important to put the functionname in the cache-key because a and a+ return slightly different results
variable sgr_cache variable sgr_cache
if {[dict exists $sgr_cache $args]} { if {[dict exists $sgr_cache a_$args]} {
return [dict get $sgr_cache $args] return [dict get $sgr_cache a_$args]
} }
#don't disable ansi here. #don't disable ansi here.
@ -2589,7 +2613,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
# explicit reset at beginning of parameter list for a= (as opposed to a+) # explicit reset at beginning of parameter list for a= (as opposed to a+)
set t [linsert $t[unset t] 0 0] set t [linsert $t[unset t] 0 0]
set result "\x1b\[[join $t {;}]m" set result "\x1b\[[join $t {;}]m"
dict set sgr_cache $args $result dict set sgr_cache a_$args $result
return $result return $result
} }
@ -4762,7 +4786,7 @@ namespace eval punk::ansi::class {
set displaycode [ansistring VIEW $code] set displaycode [ansistring VIEW $code]
if {$col eq ""} { if {$col eq ""} {
#row only move #row only move
set map [list H "H${arrow_lr}" f "f${arrow_lr}] set map [list H "H${arrow_lr}" f "f${arrow_lr}"]
} else { } else {
#row and col move #row and col move
set map [list H "H${arrow_lr}${arrow_du}" f "${arrow_lr}${arrow_du}"] set map [list H "H${arrow_lr}${arrow_du}" f "${arrow_lr}${arrow_du}"]

24
src/modules/punk/lib-999999.0a1.0.tm

@ -1111,11 +1111,12 @@ namespace eval punk::lib {
-block {trimhead1 trimtail1}\ -block {trimhead1 trimtail1}\
-line {}\ -line {}\
-commandprefix ""\ -commandprefix ""\
-ansiresets 0\ -ansiresets auto\
-ansireplays 0\
] ]
dict for {o v} $arglist { dict for {o v} $arglist {
switch -- $o { switch -- $o {
-block - -line - -commandprefix - -ansiresets {} -block - -line - -commandprefix - -ansiresets - -ansireplays {}
default { default {
error "linelist: Unrecognized option '$o' usage:$usage" error "linelist: Unrecognized option '$o' usage:$usage"
} }
@ -1174,6 +1175,17 @@ namespace eval punk::lib {
# -- --- --- --- --- --- # -- --- --- --- --- ---
set opt_ansiresets [dict get $opts -ansiresets] set opt_ansiresets [dict get $opts -ansiresets]
# -- --- --- --- --- --- # -- --- --- --- --- ---
set opt_ansireplays [dict get $opts -ansireplays]
if {$opt_ansireplays} {
if {$opt_ansiresets eq "auto"} {
set opt_ansiresets 1
}
} else {
if {$opt_ansiresets eq "auto"} {
set opt_ansiresets 0
}
}
# -- --- --- --- --- ---
set linelist [list] set linelist [list]
set nlsplit [split $text \n] set nlsplit [split $text \n]
if {![llength $opt_line]} { if {![llength $opt_line]} {
@ -1260,17 +1272,23 @@ namespace eval punk::lib {
#review - we need to make sure ansiresets don't accumulate/grow on any line #review - we need to make sure ansiresets don't accumulate/grow on any line
#Each resulting line should have a reset of some type at start and a pure-reset at end to stop #Each resulting line should have a reset of some type at start and a pure-reset at end to stop
#see if we can find an ST sequence that most terminals will not display for marking sections? #see if we can find an ST sequence that most terminals will not display for marking sections?
if {$opt_ansiresets} { if {$opt_ansireplays} {
package require punk::ansi package require punk::ansi
if {$opt_ansiresets} {
set RST [punk::ansi::a] set RST [punk::ansi::a]
} else {
set RST ""
}
set replaycodes $RST ;#todo - default? set replaycodes $RST ;#todo - default?
set transformed [list] set transformed [list]
#shortcircuit common case of no ansi #shortcircuit common case of no ansi
if {![punk::ansi::ta::detect $linelist]} { if {![punk::ansi::ta::detect $linelist]} {
if {$opt_ansiresets} {
foreach ln $linelist { foreach ln $linelist {
lappend transformed $RST$ln$RST lappend transformed $RST$ln$RST
} }
set linelist $transformed set linelist $transformed
}
} else { } else {
#INLINE punk::ansi::codetype::is_sgr_reset #INLINE punk::ansi::codetype::is_sgr_reset

4
src/modules/punk/repl-0.1.tm

@ -1879,7 +1879,7 @@ proc repl::repl_process_data {inputchan type chunk stdinlines prompt_config} {
} else { } else {
set info [a+ green]$info[a] set info [a+ green]$info[a]
} }
set lines [lines_as_list -ansiresets 1 $info] set lines [lines_as_list -ansireplays 1 $info]
if {[llength $lines] > 20} { if {[llength $lines] > 20} {
set lines [lrange $lines end-19 end] set lines [lrange $lines end-19 end]
set info [list_as_lines $lines] set info [list_as_lines $lines]
@ -1901,7 +1901,7 @@ proc repl::repl_process_data {inputchan type chunk stdinlines prompt_config} {
if {[catch { if {[catch {
#set info [$editbuf view_lines] #set info [$editbuf view_lines]
set info [$editbuf view_lines_numbered] set info [$editbuf view_lines_numbered]
set lines [lines_as_list -ansiresets 1 $info] set lines [lines_as_list -ansireplays 1 $info]
if {[llength $lines] > 20} { if {[llength $lines] > 20} {
set lines [lrange $lines end-19 end] set lines [lrange $lines end-19 end]
set info [list_as_lines $lines] set info [list_as_lines $lines]

1231
src/modules/textblock-999999.0a1.0.tm

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save