2012-01-30 71 views
1

我打算强调用户输入,但在做研究后,我仍然无法找到实现方法。下划线用户输入

到目前为止,这是我从研究中得到的结果,但它仍然无效。 任何人都知道如何解决它?或者更恰当的方法来做到这一点?

如果我正在使用,请阅读-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 
} 

感谢那些谁提前帮助! 干杯!

回答

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数据库来获取相关的escape(/ whatever)序列。为强调和关闭的terminfo能力名字是“SMUL”和“RMUL”:

read -p "Please enter your name: $(tput smul)" name 
tput rmul 
2

退房此链接here

但它只是:

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

的关键部分是\033[4m强调和\033[0m改回。

+0

喜Grammin,如果我使用的是什么 读-p“你叫什么名字?:”名字 – Andres 2012-01-30 15:21:48

+0

@Andres我会做一些事情:echo -n“你叫什么名字”;阅读var;回声“\ 033 [4mHi $ var \ 033 [0m” – Grammin 2012-01-30 15:32:00