|
|
|
@ -702,6 +702,21 @@ namespace eval punk::console { |
|
|
|
|
|
|
|
|
|
|
|
-terminal -default {stdin stdout} -type list -help\ |
|
|
|
-terminal -default {stdin stdout} -type list -help\ |
|
|
|
"terminal (currently list of in/out channels) (todo - object?)" |
|
|
|
"terminal (currently list of in/out channels) (todo - object?)" |
|
|
|
|
|
|
|
-passthrough -default "" -choices {tmux auto} -choicecolumns 1 -choicelabels { |
|
|
|
|
|
|
|
tmux\ |
|
|
|
|
|
|
|
{ Wrap ANSI sequence with tmux passthrough sequence. |
|
|
|
|
|
|
|
\x1bPtmux\;<originalsequence_with_escapes_doubled>\x1b\\ |
|
|
|
|
|
|
|
Note that a tmux session could be connected to multiple |
|
|
|
|
|
|
|
terminals (perhaps of different types) - in which case multiple |
|
|
|
|
|
|
|
responses may be received. Passthrough should generally |
|
|
|
|
|
|
|
be avoided except for debug/test purposes. |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
auto\ |
|
|
|
|
|
|
|
{ Use existence of ::env(TMUX) to detect tmux and |
|
|
|
|
|
|
|
send tmux passthrough sequence. |
|
|
|
|
|
|
|
Not recommended except for debug/test purposes. |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
-expected_ms -default 300 -type integer -help\ |
|
|
|
-expected_ms -default 300 -type integer -help\ |
|
|
|
"Expected number of ms for response from terminal. |
|
|
|
"Expected number of ms for response from terminal. |
|
|
|
100ms is usually plenty for a local terminal and a |
|
|
|
100ms is usually plenty for a local terminal and a |
|
|
|
@ -731,6 +746,7 @@ namespace eval punk::console { |
|
|
|
set expected [dict get $opts -expected_ms] |
|
|
|
set expected [dict get $opts -expected_ms] |
|
|
|
set ignoreok [dict get $opts -ignoreok] |
|
|
|
set ignoreok [dict get $opts -ignoreok] |
|
|
|
set returntype [dict get $opts -return] |
|
|
|
set returntype [dict get $opts -return] |
|
|
|
|
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
set query [dict get $values query] |
|
|
|
set query [dict get $values query] |
|
|
|
set capturingendregex [dict get $values capturingendregex] |
|
|
|
set capturingendregex [dict get $values capturingendregex] |
|
|
|
|
|
|
|
|
|
|
|
@ -837,9 +853,15 @@ namespace eval punk::console { |
|
|
|
#write before console enableRaw vs after?? |
|
|
|
#write before console enableRaw vs after?? |
|
|
|
#There seem to be problems (e.g on WSL) if we write too early - the output ends up on screen but we don't read it |
|
|
|
#There seem to be problems (e.g on WSL) if we write too early - the output ends up on screen but we don't read it |
|
|
|
|
|
|
|
|
|
|
|
#zellij? screen? |
|
|
|
switch -- $passthrough { |
|
|
|
if {[info exists ::env(TMUX)]} { |
|
|
|
auto { |
|
|
|
set query "\x1bPtmux\;[string map [list \x1b \x1b\x1b] $query]\x1b\\" |
|
|
|
if {[info exists ::env(TMUX)]} { |
|
|
|
|
|
|
|
set query "\x1bPtmux\;[string map [list \x1b \x1b\x1b] $query]\x1b\\" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tmux { |
|
|
|
|
|
|
|
set query "\x1bPtmux\;[string map [list \x1b \x1b\x1b] $query]\x1b\\" |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
puts -nonewline $output $query;flush $output |
|
|
|
puts -nonewline $output $query;flush $output |
|
|
|
chan configure $input -blocking 0 |
|
|
|
chan configure $input -blocking 0 |
|
|
|
@ -1348,6 +1370,7 @@ namespace eval punk::console { |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-terminal -default {stdin stdout} -type list -help\ |
|
|
|
-terminal -default {stdin stdout} -type list -help\ |
|
|
|
"terminal (currently list of in/out channels) (todo - object?)" |
|
|
|
"terminal (currently list of in/out channels) (todo - object?)" |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
-expected_ms -type integer -default 500 -help\ |
|
|
|
-expected_ms -type integer -default 500 -help\ |
|
|
|
"Number of ms to wait for response" |
|
|
|
"Number of ms to wait for response" |
|
|
|
@values -min 1 -max 1 |
|
|
|
@values -min 1 -max 1 |
|
|
|
@ -1361,11 +1384,12 @@ namespace eval punk::console { |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
set request [dict get $values request] |
|
|
|
set request [dict get $values request] |
|
|
|
set inoutchannels [dict get $opts -terminal] |
|
|
|
set inoutchannels [dict get $opts -terminal] |
|
|
|
|
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
set expected [dict get $opts -expected_ms] |
|
|
|
set expected [dict get $opts -expected_ms] |
|
|
|
|
|
|
|
|
|
|
|
set capturingregex {(((.*)))$} ;#capture entire response same as response-payload |
|
|
|
set capturingregex {(((.*)))$} ;#capture entire response same as response-payload |
|
|
|
set ts_start [clock millis] |
|
|
|
set ts_start [clock millis] |
|
|
|
set response [punk::console::internal::get_ansi_response_payload -ignoreok 1 -return dict -expected_ms $expected -terminal $inoutchannels $request $capturingregex] |
|
|
|
set response [punk::console::internal::get_ansi_response_payload -ignoreok 1 -return dict -expected_ms $expected -terminal $inoutchannels -passthrough $passthrough $request $capturingregex] |
|
|
|
set ts_end [clock millis] |
|
|
|
set ts_end [clock millis] |
|
|
|
puts stderr $response |
|
|
|
puts stderr $response |
|
|
|
set out "" |
|
|
|
set out "" |
|
|
|
@ -1786,6 +1810,7 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
@values -min 1 -max 1 |
|
|
|
@values -min 1 -max 1 |
|
|
|
mode -type {int|string} -multiple 0 -help\ |
|
|
|
mode -type {int|string} -multiple 0 -help\ |
|
|
|
"integer for DEC mode, or name as in the dict: |
|
|
|
"integer for DEC mode, or name as in the dict: |
|
|
|
@ -1800,8 +1825,9 @@ namespace eval punk::console { |
|
|
|
proc dec_get_mode {args} { |
|
|
|
proc dec_get_mode {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_get_mode] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_get_mode] |
|
|
|
lassign [dict values $argd] leaders opts values |
|
|
|
lassign [dict values $argd] leaders opts values |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set mode [dict get $values mode] |
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
|
|
|
|
set mode [dict get $values mode] |
|
|
|
|
|
|
|
|
|
|
|
if {[string is integer -strict $mode]} { |
|
|
|
if {[string is integer -strict $mode]} { |
|
|
|
set m $mode |
|
|
|
set m $mode |
|
|
|
@ -1815,7 +1841,7 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[\?%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[\?%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set request "\x1b\[?$m\$p" |
|
|
|
set request "\x1b\[?$m\$p" |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $terminal $request $capturingregex] |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $terminal -passthrough $passthrough $request $capturingregex] |
|
|
|
return $payload |
|
|
|
return $payload |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1936,6 +1962,7 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
-refresh -type none -help\ |
|
|
|
-refresh -type none -help\ |
|
|
|
"Force a re-test of the mode." |
|
|
|
"Force a re-test of the mode." |
|
|
|
-return -type string -choices {dict result} -default result -choicelabels { |
|
|
|
-return -type string -choices {dict result} -default result -choicelabels { |
|
|
|
@ -1953,7 +1980,8 @@ namespace eval punk::console { |
|
|
|
proc dec_has_mode {args} { |
|
|
|
proc dec_has_mode {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_has_mode] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_has_mode] |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
set console [dict get $opts -console] |
|
|
|
set console [dict get $opts -console] |
|
|
|
|
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
set num_or_name [dict get $values mode] |
|
|
|
set num_or_name [dict get $values mode] |
|
|
|
set do_refresh [dict exists $received -refresh] |
|
|
|
set do_refresh [dict exists $received -refresh] |
|
|
|
set return [dict get $opts -return] |
|
|
|
set return [dict get $opts -return] |
|
|
|
@ -1969,21 +1997,23 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
variable dec_has_mode_cache |
|
|
|
variable dec_has_mode_cache |
|
|
|
|
|
|
|
#make sure we cache on both console and passthrough |
|
|
|
|
|
|
|
set cachekey "$console $passthrough" |
|
|
|
if {$do_refresh} { |
|
|
|
if {$do_refresh} { |
|
|
|
if {[dict exists $dec_has_mode_cache $console $m]} { |
|
|
|
if {[dict exists $dec_has_mode_cache $cachekey $m]} { |
|
|
|
dict unset dec_has_mode_cache $console $m |
|
|
|
dict unset dec_has_mode_cache $cachekey $m |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if {![dict exists $dec_has_mode_cache $console $m]} { |
|
|
|
if {![dict exists $dec_has_mode_cache $cachekey $m]} { |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[\?%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[\?%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set request "\x1b\[?$m\$p" |
|
|
|
set request "\x1b\[?$m\$p" |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $console $request $capturingregex] |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $console -passthrough $passthrough $request $capturingregex] |
|
|
|
#set has_mode [expr {$payload != 0}] |
|
|
|
#set has_mode [expr {$payload != 0}] |
|
|
|
#we can use the payload result as the response as non-zero responses evaluate to true |
|
|
|
#we can use the payload result as the response as non-zero responses evaluate to true |
|
|
|
set has_mode $payload |
|
|
|
set has_mode $payload |
|
|
|
if {$has_mode ne ""} { |
|
|
|
if {$has_mode ne ""} { |
|
|
|
dict set dec_has_mode_cache $console $m $has_mode |
|
|
|
dict set dec_has_mode_cache $cachekey $m $has_mode |
|
|
|
set source "query" |
|
|
|
set source "query" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
#don't cache an empty/failed response - review |
|
|
|
#don't cache an empty/failed response - review |
|
|
|
@ -1991,7 +2021,7 @@ namespace eval punk::console { |
|
|
|
set source "failedquery" |
|
|
|
set source "failedquery" |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
set has_mode [dict get $dec_has_mode_cache $console $m] |
|
|
|
set has_mode [dict get $dec_has_mode_cache $cachekey $m] |
|
|
|
set source "cache" |
|
|
|
set source "cache" |
|
|
|
} |
|
|
|
} |
|
|
|
if {$return eq "dict"} { |
|
|
|
if {$return eq "dict"} { |
|
|
|
@ -2009,6 +2039,7 @@ namespace eval punk::console { |
|
|
|
{Show table of DEC modes with basic information.} |
|
|
|
{Show table of DEC modes with basic information.} |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
-test -type none -help\ |
|
|
|
-test -type none -help\ |
|
|
|
"Test current value/support for each mode" |
|
|
|
"Test current value/support for each mode" |
|
|
|
-supported -type none -help\ |
|
|
|
-supported -type none -help\ |
|
|
|
@ -2020,8 +2051,9 @@ namespace eval punk::console { |
|
|
|
proc dec_modes {args} { |
|
|
|
proc dec_modes {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_modes] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::dec_modes] |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set do_test [dict exists $received -test] |
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
|
|
|
|
set do_test [dict exists $received -test] |
|
|
|
set only_supported [dict exists $received -supported] |
|
|
|
set only_supported [dict exists $received -supported] |
|
|
|
if {[dict exists $values match]} { |
|
|
|
if {[dict exists $values match]} { |
|
|
|
set matches [dict get $values match] |
|
|
|
set matches [dict get $values match] |
|
|
|
@ -2079,7 +2111,7 @@ namespace eval punk::console { |
|
|
|
set RST "" |
|
|
|
set RST "" |
|
|
|
if {$do_test} { |
|
|
|
if {$do_test} { |
|
|
|
#dec_has_mode can be cached - in which case only 0|3|4 can be relied upon without re-querying |
|
|
|
#dec_has_mode can be cached - in which case only 0|3|4 can be relied upon without re-querying |
|
|
|
set hasmode_dict [dec_has_mode -console $terminal -return dict $code] |
|
|
|
set hasmode_dict [dec_has_mode -console $terminal -passthrough $passthrough -return dict $code] |
|
|
|
switch -- [dict get $hasmode_dict result] { |
|
|
|
switch -- [dict get $hasmode_dict result] { |
|
|
|
0 { |
|
|
|
0 { |
|
|
|
if {$only_supported} { |
|
|
|
if {$only_supported} { |
|
|
|
@ -2094,7 +2126,7 @@ namespace eval punk::console { |
|
|
|
1 - 2 { |
|
|
|
1 - 2 { |
|
|
|
if {[dict get $hasmode_dict source] eq "cache"} { |
|
|
|
if {[dict get $hasmode_dict source] eq "cache"} { |
|
|
|
#a terminal query is required |
|
|
|
#a terminal query is required |
|
|
|
set testresult [dec_get_mode -console $terminal $code] |
|
|
|
set testresult [dec_get_mode -console $terminal -passthrough $passthrough $code] |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
set testresult [dict get $hasmode_dict result] |
|
|
|
set testresult [dict get $hasmode_dict result] |
|
|
|
if {![string is integer -strict $testresult]} { |
|
|
|
if {![string is integer -strict $testresult]} { |
|
|
|
@ -2140,7 +2172,7 @@ namespace eval punk::console { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if {$only_supported} { |
|
|
|
if {$only_supported} { |
|
|
|
#dec_has_mode still queries terminal - but is cached if a response was received |
|
|
|
#dec_has_mode still queries terminal - but is cached if a response was received |
|
|
|
if {[dec_has_mode -console $terminal $code] == 0} { |
|
|
|
if {[dec_has_mode -console $terminal -passthrough $passthrough $code] == 0} { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -2189,6 +2221,7 @@ namespace eval punk::console { |
|
|
|
source indicates whether the result came |
|
|
|
source indicates whether the result came |
|
|
|
from query or cache." |
|
|
|
from query or cache." |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
@values -min 1 -max 1 |
|
|
|
@values -min 1 -max 1 |
|
|
|
mode -type {int|string} -help\ |
|
|
|
mode -type {int|string} -help\ |
|
|
|
"integer for ANSI mode, or name as in the dict: |
|
|
|
"integer for ANSI mode, or name as in the dict: |
|
|
|
@ -2198,10 +2231,11 @@ namespace eval punk::console { |
|
|
|
proc ansi_has_mode {args} { |
|
|
|
proc ansi_has_mode {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_has_mode] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_has_mode] |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
set console [dict get $opts -console] |
|
|
|
set console [dict get $opts -console] |
|
|
|
set num_or_name [dict get $values mode] |
|
|
|
set num_or_name [dict get $values mode] |
|
|
|
set return [dict get $opts -return] |
|
|
|
set return [dict get $opts -return] |
|
|
|
set do_refresh [dict exists $received -refresh] |
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
|
|
|
|
set do_refresh [dict exists $received -refresh] |
|
|
|
|
|
|
|
|
|
|
|
if {[string is integer -strict $num_or_name]} { |
|
|
|
if {[string is integer -strict $num_or_name]} { |
|
|
|
set m $num_or_name |
|
|
|
set m $num_or_name |
|
|
|
@ -2214,20 +2248,22 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
variable ansi_has_mode_cache |
|
|
|
variable ansi_has_mode_cache |
|
|
|
|
|
|
|
#make sure we cache on both console and passthrough |
|
|
|
|
|
|
|
set cachekey "$console $passthrough" |
|
|
|
if {$do_refresh} { |
|
|
|
if {$do_refresh} { |
|
|
|
if {[dict exists $ansi_has_mode_cache $console $m]} { |
|
|
|
if {[dict exists $ansi_has_mode_cache $cachekey $m]} { |
|
|
|
dict unset ansi_has_mode_cache $console $m |
|
|
|
dict unset ansi_has_mode_cache $cachekey $m |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if {![dict exists $ansi_has_mode_cache $console $m]} { |
|
|
|
if {![dict exists $ansi_has_mode_cache $cachekey $m]} { |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set request "\x1b\[$m\$p" |
|
|
|
set request "\x1b\[$m\$p" |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $console $request $capturingregex] |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $console -passthrough $passthrough $request $capturingregex] |
|
|
|
#set has_mode [expr {$payload != 0}] |
|
|
|
#set has_mode [expr {$payload != 0}] |
|
|
|
set has_mode $payload |
|
|
|
set has_mode $payload |
|
|
|
if {$has_mode ne ""} { |
|
|
|
if {$has_mode ne ""} { |
|
|
|
dict set ansi_has_mode_cache $console $m $has_mode |
|
|
|
dict set ansi_has_mode_cache $cachekey $m $has_mode |
|
|
|
set source "query" |
|
|
|
set source "query" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
#don't cache an empty/failed response - review |
|
|
|
#don't cache an empty/failed response - review |
|
|
|
@ -2235,7 +2271,7 @@ namespace eval punk::console { |
|
|
|
set source "failedquery" |
|
|
|
set source "failedquery" |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
set has_mode [dict get $ansi_has_mode_cache $console $m] |
|
|
|
set has_mode [dict get $ansi_has_mode_cache $cachekey $m] |
|
|
|
set source "cache" |
|
|
|
set source "cache" |
|
|
|
} |
|
|
|
} |
|
|
|
if {$return eq "dict"} { |
|
|
|
if {$return eq "dict"} { |
|
|
|
@ -2366,6 +2402,7 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
@values -min 1 -max 1 |
|
|
|
@values -min 1 -max 1 |
|
|
|
mode -type {int|string} -multiple 0 -help\ |
|
|
|
mode -type {int|string} -multiple 0 -help\ |
|
|
|
"integer for ANSI mode, or name as in the dict: |
|
|
|
"integer for ANSI mode, or name as in the dict: |
|
|
|
@ -2380,8 +2417,9 @@ namespace eval punk::console { |
|
|
|
proc ansi_get_mode {args} { |
|
|
|
proc ansi_get_mode {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_get_mode] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_get_mode] |
|
|
|
lassign [dict values $argd] leaders opts values |
|
|
|
lassign [dict values $argd] leaders opts values |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set mode [dict get $values mode] |
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
|
|
|
|
set mode [dict get $values mode] |
|
|
|
|
|
|
|
|
|
|
|
if {[string is integer -strict $mode]} { |
|
|
|
if {[string is integer -strict $mode]} { |
|
|
|
set m $mode |
|
|
|
set m $mode |
|
|
|
@ -2395,7 +2433,7 @@ namespace eval punk::console { |
|
|
|
} |
|
|
|
} |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set capturingregex [string map [list %MODE% $m] {(.*)(\x1b\[%MODE%;([0-9]+)\$y)$}] ;#must capture prefix,entire-response,response-payload |
|
|
|
set request "\x1b\[$m\$p" |
|
|
|
set request "\x1b\[$m\$p" |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $terminal $request $capturingregex] |
|
|
|
set payload [punk::console::internal::get_ansi_response_payload -terminal $terminal -passthrough $passthrough $request $capturingregex] |
|
|
|
return $payload |
|
|
|
return $payload |
|
|
|
} |
|
|
|
} |
|
|
|
#todo ansi_unset_mode |
|
|
|
#todo ansi_unset_mode |
|
|
|
@ -2409,6 +2447,7 @@ namespace eval punk::console { |
|
|
|
{Show table of ANSI modes with basic information.} |
|
|
|
{Show table of ANSI modes with basic information.} |
|
|
|
@opts |
|
|
|
@opts |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
-console -type list -minsize 2 -default {stdin stdout} |
|
|
|
|
|
|
|
${[punk::args::resolved_def -types opts ::punk::console::internal::get_ansi_response_payload -passthrough]} |
|
|
|
-test -type none -help\ |
|
|
|
-test -type none -help\ |
|
|
|
"Test current value/support for each mode" |
|
|
|
"Test current value/support for each mode" |
|
|
|
-supported -type none -help\ |
|
|
|
-supported -type none -help\ |
|
|
|
@ -2420,8 +2459,9 @@ namespace eval punk::console { |
|
|
|
proc ansi_modes {args} { |
|
|
|
proc ansi_modes {args} { |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_modes] |
|
|
|
set argd [punk::args::parse $args withid ::punk::console::ansi_modes] |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
lassign [dict values $argd] leaders opts values received |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set terminal [dict get $opts -console] |
|
|
|
set do_test [dict exists $received -test] |
|
|
|
set passthrough [dict get $opts -passthrough] |
|
|
|
|
|
|
|
set do_test [dict exists $received -test] |
|
|
|
if {[dict exists $values match]} { |
|
|
|
if {[dict exists $values match]} { |
|
|
|
set matches [dict get $values match] |
|
|
|
set matches [dict get $values match] |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -2505,7 +2545,7 @@ namespace eval punk::console { |
|
|
|
set reset_state_colour "" |
|
|
|
set reset_state_colour "" |
|
|
|
set RST "" |
|
|
|
set RST "" |
|
|
|
if {$do_test} { |
|
|
|
if {$do_test} { |
|
|
|
set hasmode_dict [ansi_has_mode -console $terminal -return dict $code] |
|
|
|
set hasmode_dict [ansi_has_mode -console $terminal -passthrough $passthrough -return dict $code] |
|
|
|
switch -- [dict get $hasmode_dict result] { |
|
|
|
switch -- [dict get $hasmode_dict result] { |
|
|
|
0 { |
|
|
|
0 { |
|
|
|
if {$only_supported} { |
|
|
|
if {$only_supported} { |
|
|
|
@ -2520,7 +2560,7 @@ namespace eval punk::console { |
|
|
|
1 - 2 { |
|
|
|
1 - 2 { |
|
|
|
if {[dict get $hasmode_dict source] eq "cache"} { |
|
|
|
if {[dict get $hasmode_dict source] eq "cache"} { |
|
|
|
#a terminal query is required |
|
|
|
#a terminal query is required |
|
|
|
set testresult [ansi_get_mode -console $terminal $code] |
|
|
|
set testresult [ansi_get_mode -console $terminal -passthrough $passthrough $code] |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
set testresult [dict get $hasmode_dict result] |
|
|
|
set testresult [dict get $hasmode_dict result] |
|
|
|
if {![string is integer -strict $testresult]} { |
|
|
|
if {![string is integer -strict $testresult]} { |
|
|
|
@ -2566,7 +2606,7 @@ namespace eval punk::console { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if {$only_supported} { |
|
|
|
if {$only_supported} { |
|
|
|
#ansi_has_mode still queries terminal - but is cached if a response was received |
|
|
|
#ansi_has_mode still queries terminal - but is cached if a response was received |
|
|
|
if {[ansi_has_mode -console $terminal $code] == 0} { |
|
|
|
if {[ansi_has_mode -console $terminal -passthrough $passthrough $code] == 0} { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|