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