Bash script user invitation

I'm having problems with my well-known methods for generating data entry prompts:

read -p "Input something: " variabile

This causes problems when trying to use the arrow keys, it echoes the ANSI code for each step of the arrow key

read -e -p "Input something: " variable

This fixes the problem with the arrow keys, but when reaching the terminal width, text input does not continue on a new line, but on the same line, overwriting the (visually) existing input

echo -n "Input something: "; read -e variable

This apparently fixes the problems as previously described ... until I find that typing something and then pressing backspace overwrites the prompt, and also, when the input is longer, the visual rewriting appears again from the second new line of input.

So, is there a good way to create queries without the above problems?

UPDATE

, read -e -p :

highlight=$(echo -e "\e[1;97m")
clear=$(echo -e "\e[0m")
read -e -p "Input$highlight something$clear: " variable

read ( , , ), , , .

+4
2

dimo414, readline , , . escape- . , , escape-

echo ${#highlight}

bash PS1, ​​escape- "\[" "\]", readline , , escape- bash read .

read: $'\001' $'\002', BashFAQ, , , -e read. , :

read -e -p "Input "$'\001'"${highlight}"$'\002'something$'\001'"${clear}"$'\002'": "

tput, escape-, . man 5 termcap.

dotfiles bash, /, .

+1

, , , . , escape- , Bash, , escape- .

, \[ \], .

, highlight :

highlight=$(echo -e "\[\e[1;97m\]")

color pcolor Prompt.gem, :

read -e -p "Input $(pcolor DEFAULT BOLD)something$(pcolor): " variable
+1

Source: https://habr.com/ru/post/1624334/


All Articles