我正在编写一个简单的 cli 脚本,并想为以下代码添加一些颜色:
rl.question('Enter destination path: ', function(answer) {
// ...
});
rl.write('/home/' + user + '/bin');
在终端中显示:
Enter destination path: /home/jmcateer/bin_
但我想为提示添加一些颜色,我做了以下操作:
rl.question('\u001b[1;36mEnter destination path:\u001b[0m ', function(answer) {
});
rl.write('/home/' + user + '/bin');
命令行提示符最终显示:
Enter destination path: /home/jmcateer/bin_
它可以工作,但是我宁愿没有大量的空白。有没有人对如何处理这个有任何想法?
编辑:
我无法通过退格来删除空格...当我尝试使用退格键时,空格会像这样跳到另一端
Enter destination path: /home/jmcateer/bin_
Enter destination path: /home/jmcateer/bi _
Enter destination path: /home/jmcateer/b _
...
Enter destination path: _
此时退格无效。