Search code examples
bashterminaloutputshuser-input

How to stop user input to show on interactive terminal window?


Here is an example of script:

while true; do 
printf ""
done

Now if I run this script on a interactive terminal it obviously print nothing!

but in same case if I also start typing CHARACTERS and KEYS from my keyboard they will obviously show on terminal window while the script is running interactively.

Example output:

fasd^[[D^[[A^[[Cfsf

I want to temporarily stop user input to show while script is still running.

Thankyou, for any help.


Solution

  • In my piu-piu project I'm switching user input on and off like this:

    ...
    COF='\e[?25l' #Cursor Off
    CON='\e[?25h' #Cursor On
    
    cursor () {
        case $1 in
             on) stty  echo; printf "$CON";;
            off) stty -echo; printf "$COF";;
        esac
    }
    ...
    
    cursor on
    cursor off
    ...