Browse Source

tsv for console is_raw - to sync between repl and codethread

master
Julian Noble 2 months ago
parent
commit
c0aa7a9023
  1. 2
      src/modules/punk/basictelnet-999999.0a1.0.tm
  2. 39
      src/modules/punk/console-999999.0a1.0.tm
  3. 2
      src/modules/punk/lib-999999.0a1.0.tm
  4. 15
      src/modules/punk/repl-0.1.tm

2
src/modules/punk/basictelnet-999999.0a1.0.tm

@ -525,7 +525,7 @@ namespace eval punk::basictelnet {
# - review
#if we didn't make agreement that server would echo and we're in raw mode
if {![dict get $server_option_state 1] && $::punk::console::is_raw} {
if {![dict get $server_option_state 1] && [tsv::get console is_raw]} {
puts -nonewline stdout $chunk
}
# -- --- --- ---

39
src/modules/punk/console-999999.0a1.0.tm

@ -44,6 +44,7 @@
#[list_begin itemized]
package require Tcl 8.6-
package require Thread ;#tsv required to sync is_raw
package require punk::ansi
#*** !doctools
#[item] [package {Tcl 8.6-}]
@ -84,7 +85,12 @@ namespace eval punk::console {
variable previous_stty_state_stdin ""
variable previous_stty_state_stdout ""
variable previous_stty_state_stderr ""
variable is_raw 0
#variable is_raw 0
if {![tsv::exists console is_raw]} {
tsv::set console is_raw 0
}
variable input_chunks_waiting
if {![info exists input_chunks_waiting(stdin)]} {
set input_chunks_waiting(stdin) [list]
@ -183,7 +189,8 @@ namespace eval punk::console {
#NOTE - the is_raw is only being set in current interp - but the channel is shared.
#this is problematic with the repl thread being separate. - must be a tsv? REVIEW
proc enableRaw {{channel stdin}} {
variable is_raw
#variable is_raw
variable previous_stty_state_$channel
set sttycmd [auto_execok stty]
if {[set previous_stty_state_$channel] eq ""} {
@ -193,21 +200,21 @@ namespace eval punk::console {
}
exec {*}$sttycmd raw -echo <@$channel
set is_raw 1
tsv::set console is_raw 1
return [dict create previous [set previous_stty_state_$channel]]
}
proc disableRaw {{channel stdin}} {
variable is_raw
#variable is_raw
variable previous_stty_state_$channel
set sttycmd [auto_execok stty]
if {[set previous_stty_state_$channel] ne ""} {
exec {*}$sttycmd [set previous_stty_state_$channel]
set previous_stty_state_$channel ""
set is_raw 0
tsv::set console is_raw 0
return restored
}
exec {*}$sttycmd -raw echo <@$channel
set is_raw 0
tsv::set console is_raw 0
return done
}
proc enableVirtualTerminal {{channels {input output}}} {
@ -249,11 +256,11 @@ namespace eval punk::console {
}
proc mode {{raw_or_line query}} {
variable is_raw
#variable is_raw
variable ansi_available
set raw_or_line [string tolower $raw_or_line]
if {$raw_or_line eq "query"} {
if {$is_raw} {
if {[tsv::get console is_raw]} {
return "raw"
} else {
return "line"
@ -493,7 +500,7 @@ namespace eval punk::console {
}
proc [namespace parent]::enableRaw {{channel stdin}} {
variable is_raw
#variable is_raw
variable previous_stty_state_$channel
if {[package provide twapi] ne ""} {
@ -506,7 +513,7 @@ namespace eval punk::console {
#set newmode [dict merge $oldmode [dict create -lineinput 0 -echoinput 0]]
set newmode [twapi::get_console_input_mode]
set is_raw 1
tsv::set console is_raw 1
#don't disable handler - it will detect is_raw
### twapi::set_console_control_handler {}
return [list stdin [list from $oldmode to $newmode]]
@ -516,7 +523,7 @@ namespace eval punk::console {
}
exec {*}$sttycmd raw -echo <@$channel
set is_raw 1
tsv::set console is_raw 1
#review - inconsistent return dict
return [dict create stdin [list from [set previous_stty_state_$channel] to "" note "fixme - to state not shown"]]
} else {
@ -528,7 +535,7 @@ namespace eval punk::console {
#could be we were missing a step in reopening stdin and console configuration?
proc [namespace parent]::disableRaw {{channel stdin}} {
variable is_raw
#variable is_raw
variable previous_stty_state_$channel
if {[package provide twapi] ne ""} {
@ -537,7 +544,7 @@ namespace eval punk::console {
# Turn on the echo and line-editing bits
twapi::modify_console_input_mode $console_handle -lineinput 1 -echoinput 1
set newmode [twapi::get_console_input_mode]
set is_raw 0
tsv::set console is_raw 0
return [list stdin [list from $oldmode to $newmode]]
} elseif {[set sttycmd [auto_execok stty]] ne ""} {
#stty can return info on windows - but doesn't seem to be able to set anything.
@ -550,7 +557,7 @@ namespace eval punk::console {
return restored
}
exec {*}$sttycmd -raw echo <@$channel
set is_raw 0
tsv::set console is_raw 0
#do we really want to exec stty yet again to show final 'to' state?
#probably not. We should work out how to read the stty result flags and set a result.. or just limit from,to to showing echo and lineedit states.
return [list stdin [list from "[set previous_stty_state_$channel]" to "" note "fixme - to state not shown"]]
@ -634,7 +641,7 @@ namespace eval punk::console {
puts -nonewline $output $query;flush $output
#todo - test and save rawstate so we don't disableRaw if console was already raw
if {!$::punk::console::is_raw} {
if {![tsv::get console is_raw]} {
set was_raw 0
punk::console::enableRaw
} else {
@ -1378,7 +1385,7 @@ namespace eval punk::console {
#todo - compare speed with get_cursor_pos - work out why the big difference
proc test_cursor_pos {} {
if {!$::punk::console::is_raw} {
if {![tsv::get console is_raw]} {
set was_raw 0
enableRaw
} else {

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

@ -2387,7 +2387,7 @@ namespace eval punk::lib {
set stdin_state [fconfigure stdin]
if {[catch {
package require punk::console
set console_raw [set ::punk::console::is_raw]
set console_raw [tsv::get console is_raw]
} err_console]} {
#assume normal line mode
set console_raw 0

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

@ -73,6 +73,7 @@ namespace eval repl {
#variable last_unknown ""
tsv::set repl last_unknown ""
tsv::set console is_raw 0
variable output ""
#important not to initialize - as it can be preset by cooperating package before app-punk has been package required
#(this is an example of a deaddrop)
@ -149,7 +150,7 @@ proc ::punk::repl::init_signal_handlers {} {
flush stderr
incr signal_control_c
#rputs stderr "* console_control: $args"
if {$::punk::console::is_raw} {
if {[tsv::get console is_raw]} {
if {[lindex $::errorCode 0] eq "CHILDKILLED"} {
#rputs stderr "\n|repl> ctrl-c errorCode: $::errorCode"
#avoid spurious triggers after interrupting a command..
@ -1297,9 +1298,11 @@ proc repl::repl_handler {inputchan prompt_config} {
if {[dict get $original_input_conf -inputmode] eq "raw"} {
#user or script has apparently put stdin into raw mode - update punk::console::is_raw to match
set rawmode 1
set ::punk::console::is_raw 1
#set ::punk::console::is_raw 1
tsv::set console is_raw 1
} else {
set ::punk::console::is_raw 0
#set ::punk::console::is_raw 0
tsv::set console is_raw 0
}
#what about enable/disable virtualTerminal ?
#using stdin -inputmode to switch modes won't set virtualterminal input state appropriately
@ -1309,7 +1312,8 @@ proc repl::repl_handler {inputchan prompt_config} {
} else {
#JMN FIX!
#this returns 0 in rawmode on 8.6 after repl thread changes
set rawmode [set ::punk::console::is_raw]
#set rawmode [set ::punk::console::is_raw]
set rawmode [tsv::get console is_raw]
}
if {!$rawmode} {
@ -1673,7 +1677,8 @@ proc repl::repl_process_data {inputchan chunktype chunk stdinlines prompt_config
set debugprompt [dict get $prompt_config debugprompt]
set rawmode [set ::punk::console::is_raw]
#set rawmode [set ::punk::console::is_raw]
set rawmode [tsv::get console is_raw]
if {!$rawmode} {
#puts stderr "-->got [ansistring VIEW -lf 1 $stdinlines]<--"

Loading…
Cancel
Save