44#
55# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7- # Last Modified: 2024-Feb-29
7+ # Last Modified: 2024-Mar-03
88# ##################################################################
99set -u
1010
11- readonly SCRIPT_VERSION=1.0.6
11+ readonly SCRIPT_VERSION=1.0.7
1212readonly SCRIPT_NAME=" MerlinAU"
1313
1414# #-------------------------------------##
@@ -1917,15 +1917,16 @@ _TestLoginCredentials_()
19171917 fi
19181918}
19191919
1920- # #-------------------------------------##
1921- # # Added by Martinski W. [2024-Feb-29 ] ##
1922- # #-------------------------------------##
1920+ # #---------------------------------------- ##
1921+ # # Modified by Martinski W. [2024-Mar-03 ] ##
1922+ # #---------------------------------------- ##
19231923_GetPasswordInput_ ()
19241924{
19251925 local PSWDstrLenMIN=1 PSWDstrLenMAX=64
19261926 local PSWDstring PSWDtmpStr PSWDprompt
1927- local retCode charNum prevChar pswdLength showPSWD
1928- local lastTabTime=0 # Added for debounce
1927+ local retCode charNum pswdLength showPSWD
1928+ # Added for TAB keypress debounce #
1929+ local lastTabTime=0 currentTime timeDiff
19291930
19301931 if [ $# -eq 0 ] || [ -z " $1 " ]
19311932 then
@@ -1934,6 +1935,15 @@ _GetPasswordInput_()
19341935 fi
19351936 PSWDprompt=" $1 "
19361937
1938+ _GetKeypress_ ()
1939+ {
1940+ local savedSettings
1941+ savedSettings=" $( stty -g) "
1942+ stty -echo raw
1943+ echo " $( dd count=1 2> /dev/null) "
1944+ stty " $savedSettings "
1945+ }
1946+
19371947 _showPSWDPrompt_ ()
19381948 {
19391949 local pswdTemp LENct LENwd
@@ -1946,7 +1956,7 @@ _GetPasswordInput_()
19461956 }
19471957
19481958 showPSWD=0
1949- charNum=" " prevChar= " "
1959+ charNum=" "
19501960 PSWDstring=" $pswdString "
19511961 pswdLength=" ${# PSWDstring} "
19521962 if [ -z " $PSWDstring " ]
@@ -1955,9 +1965,11 @@ _GetPasswordInput_()
19551965 fi
19561966 echo ; _showPSWDPrompt_
19571967
1958- while IFS=' ' read -n 1 -rs theChar
1968+ while IFS=' ' theChar= " $( _GetKeypress_ ) "
19591969 do
1960- if [ " $theChar " = " " ]
1970+ charNum=" $( printf " %d" " '$theChar " ) "
1971+
1972+ if [ " $theChar " = " " ] || [ " $charNum " -eq 13 ]
19611973 then
19621974 if [ " $pswdLength " -ge " $PSWDstrLenMIN " ] && [ " $pswdLength " -le " $PSWDstrLenMAX " ]
19631975 then
@@ -1978,37 +1990,25 @@ _GetPasswordInput_()
19781990 fi
19791991 break
19801992 fi
1981- charNum=" $( printf " %d" " '$theChar " ) "
19821993
1983- # # TAB keypress with debounce ##
1994+ # # Ignore Escape Sequences ##
1995+ [ " $charNum " -eq 27 ] && continue
1996+
1997+ # # TAB keypress as toggle with debounce ##
19841998 if [ " $charNum " -eq 9 ]
19851999 then
1986- local currentTime=$( date +%s)
1987- local timeDiff=$(( currentTime - lastTabTime))
1988- if [ " $timeDiff " -ge 1 ] # Check if at least 1 second has passed
2000+ currentTime=" $( date +%s) "
2001+ timeDiff=" $(( currentTime - lastTabTime)) "
2002+ if [ " $timeDiff " -gt 0 ]
19892003 then
19902004 showPSWD=" $(( ! showPSWD)) "
1991- lastTabTime=$currentTime # Update last TAB press time
2005+ lastTabTime=" $currentTime " # Update last TAB press time #
19922006 _showPSWDPrompt_
19932007 fi
19942008 continue
19952009 fi
19962010
1997- # # Ignore Escape Sequences ##
1998- if [ " $charNum " -eq 27 ]
1999- then prevChar=" ${charNum} " ; continue ; fi
2000-
2001- if [ -n " $prevChar " ] && \
2002- { [ " $prevChar " -eq 27 ] || \
2003- [ " $prevChar " -eq 2791 ] || \
2004- [ " $prevChar " -eq 279150 ] || \
2005- [ " $prevChar " -eq 279151 ] || \
2006- [ " $prevChar " -eq 279153 ] || \
2007- [ " $prevChar " -eq 279154 ] ; }
2008- then prevChar=" ${prevChar}${charNum} " ; continue
2009- else prevChar=" " ; fi
2010-
2011- # # Backspace keypress ##
2011+ # # BACKSPACE keypress ##
20122012 if [ " $charNum " -eq 8 ] || [ " $charNum " -eq 127 ]
20132013 then
20142014 if [ " $pswdLength " -gt 0 ]
0 commit comments