Browse Source

An attempt to fix enableRaw/disableRaw on unix-like platforms

master
Julian Noble 10 months ago
parent
commit
7ece6defbd
  1. 16
      src/modules/punk/console-999999.0a1.0.tm

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

@ -31,6 +31,9 @@ if {"windows" eq $::tcl_platform(platform)} {
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
namespace eval punk::console {
variable has_twapi 0
variable previous_stty_state_stdin ""
variable previous_stty_state_stdout ""
variable previous_stty_state_stderr ""
#punk::console namespace - contains *directly* acting functions - some based on ansi escapes from the 'ansi' sub namespace, some on local system calls or executable calls wrapped in the 'local' sub namespace
#directly acting means they write to stdout to cause the console to peform the action, or they perform the action immediately via other means.
@ -72,13 +75,26 @@ namespace eval punk::console {
proc enableAnsi {} {
#todo?
}
#todo - something better
proc enableRaw {{channel stdin}} {
variable previous_stty_state_$channel
set sttycmd [auto_execok stty]
set previous_stty_state_$channel [exec {*}$sttycmd -g <@$channel]
exec {*}$sttycmd raw -echo <@$channel
return [dict create previous $previous_stty_state_$channel]
}
proc disableRaw {{channel stdin}} {
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 ""
return restored
}
exec {*}$sttycmd raw echo <@$channel
return done
}
}

Loading…
Cancel
Save