问题描述
我有一个生成motd的bash脚本.问题取决于某些终端设置,我不确定颜色是否会延伸到行尾.有时则不会:
I have a bash script which generates a motd. The problem is depending on some terminal settings which I am not sure about the color will extend to the end of the line. Othertimes it doesn't:
例如
v.s.
IIRC只是正常的gnome终端,另一个是我的tmux术语.所以我的问题是如何使它扩展到80个字符(或实际上扩展到终端宽度).当然,我可以填充80个字符,但这确实不能解决问题.
IIRC one is just the normal gnome-terminal and the other is my tmux term. So my question is how can I get this to extend to 80 character (or really to the terminal width). Of course I can pad to 80 chars but that really doesn't solve the problem.
这是我生成代码的代码片段:
Here is a snip of my code which generates the motd:
TC_RESET="^[[0m"
TC_SKY="^[[0;37;44m"
TC_GRD="^[[0;30;42m"
TC_TEXT="^[[38;5;203m"
echo -n "${TC_SKY}
... lots of printing..."
echo -e "\n Welcome to Mokon's Linux! \n"
echo -n "${TC_GRD}"
nodeinfo # Just prints the info seen below...
echo ${TC_RESET}
我如何通过bash以编程方式更改终端设置,或将某些颜色更改为行尾?
How can I programmatically from bash change the terminal settings or something change the color to the end of the line?
推荐答案
也许使用转义序列以清除为EOL
出于某种原因(在我的MacOS终端上!),我只需要指定此序列,然后它就可以用于所有行,但是为了完整起见,我将所有序列都列出了
For some reason (on my MacOS terminal!) I only needed specify this sequence and then it worked for all the lines but for completeness I list it for all
TC_RESET=$'\x1B[0m'
TC_SKY=$'\x1B[0;37;44m'
TC_GRD=$'\x1B[0;30;42m'
TC_TEXT=$'\x1B[38;5;203m'
CLREOL=$'\x1B[K'
echo -n "${TC_SKY}${CLREOL}"
echo -e "\n ABC${CLREOL}\n"
echo -e "\n DEFG${CLREOL}\n"
echo -n "${TC_GRD}"
echo -e "\n ABC${CLREOL}\n"
echo -e "\n DEFG${CLREOL}\n"
echo ${TC_RESET}
这篇关于将终端颜色扩展到行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!