From e26f84228bd25e3073aa63160733f971e954169d Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Sat, 3 Feb 2024 01:32:42 +1100 Subject: [PATCH] another attempt at fixing enableRaw/disableRaw on unix --- src/modules/punk/console-999999.0a1.0.tm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/punk/console-999999.0a1.0.tm b/src/modules/punk/console-999999.0a1.0.tm index 08b0143..f3a110a 100644 --- a/src/modules/punk/console-999999.0a1.0.tm +++ b/src/modules/punk/console-999999.0a1.0.tm @@ -59,6 +59,7 @@ namespace eval punk::console { internal::abort_if_loop tailcall enableAnsi } + #review what raw mode means with regard to a specific channel vs terminal as a whole proc enableRaw {{channel stdin}} { #loopavoidancetoken (don't remove) internal::define_windows_procs @@ -76,14 +77,16 @@ namespace eval punk::console { #todo? } - #todo - something better + #todo - something better - the 'channel' concept may not really apply on unix, as raw mode is for input and output modes proc enableRaw {{channel stdin}} { variable previous_stty_state_$channel set sttycmd [auto_execok stty] - set previous_stty_state_$channel [exec {*}$sttycmd -g <@$channel] + if {[set previous_stty_state_$channel] eq ""} { + set previous_stty_state_$channel [exec {*}$sttycmd -g <@$channel] + } exec {*}$sttycmd raw -echo <@$channel - return [dict create previous $previous_stty_state_$channel] + return [dict create previous [set previous_stty_state_$channel]] } proc disableRaw {{channel stdin}} { variable previous_stty_state_$channel @@ -93,7 +96,7 @@ namespace eval punk::console { set previous_stty_state_$channel "" return restored } - exec {*}$sttycmd raw echo <@$channel + exec {*}$sttycmd -raw echo <@$channel return done } }