运行Ruby脚本时更改bash终端输出颜色 [英] change bash terminal output color while running Ruby script
本文介绍了运行Ruby脚本时更改bash终端输出颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想简短地更改终端输出颜色,运行Ruby脚本,以便标准输出以更改后的颜色打印,睡眠"一秒钟,然后再将其更改回去.我知道如何设置颜色,就像提示一样:
I'd like to briefly change my terminal output color, run a Ruby script so that the stdout prints in that changed color, 'sleep' for a second, then change it back. I know how to set colors, like for the prompt:
PS1="\e[0;36m[\w] \e[m "
我想我需要编写一个bash函数来做到这一点.那会是什么样?
I imagine I need to write a bash function to do this. What would that look like?
推荐答案
这是一个红宝石脚本,用于显示所有终端颜色.下载或运行下面的代码.
Here is a ruby script to show all the terminal colors. Download it or run the code below.
def color(index)
normal = "\e[#{index}m#{index}\e[0m"
bold = "\e[#{index}m\e[1m#{index}\e[0m"
"#{normal} #{bold} "
end
8.times do|index|
line = color(index + 1)
line += color(index + 30)
line += color(index + 90)
line += color(index + 40)
line += color(index + 100)
puts line
end
这篇关于运行Ruby脚本时更改bash终端输出颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文