强调用户输入

时间:2012-01-30 14:59:47

标签: linux bash shell underline

我打算强调用户输入,但经过研究后,我仍然无法找到方法。

到目前为止,这是我从研究中得到的,但它仍然无法发挥作用。 谁知道怎么解决?或者更确切地说是正确的方法吗?

如果我使用读取-p"您的名字是什么:"名称而不是下面的那个?正如我对输出所期望的那样。

你叫什么名字? (来自用户的输入并加下划线)

function underlineInput()
{
PS1='\033[4;47;40m'
}

function UNunderlineInput()
{
PS1='\033[0;47;40m'
}

function hi()
{
echo "Please enter your name: "
underlineInput
read input
underlineInput
}

感谢那些提前帮助的人! 干杯!

2 个答案:

答案 0 :(得分:2)

请查看此链接here

但它只是:

$ echo -e "\033[4mThis is a underlined line.\033[0m"

关键部分是要加下划线的\033[4m和要更改回来的\033[0m

答案 1 :(得分:1)

将转义序列设置为在提示结束时打开下划线,然后发送返回正常序列:

read -p $'Please enter your name: \033[4m' name
printf '\033[0m' # Use printf instead of echo to avoid newline, and it translates escape without $''

顺便说一句,如果您希望此脚本也适用于其他类型的终端,您可以使用terminfo数据库来获取相关的转义(/无论)序列。用于加下划线的terminfo功能名称是“smul”和“rmul”:

read -p "Please enter your name: $(tput smul)" name
tput rmul
相关问题