有很多着色库:彩色,term-ansicolor.
但有没有可以做到这一点:
但有没有可以做到这一点:
puts "#{'hello'.red} world!".bold
和世界!应该是大胆的.
为了说清楚,我想得到这个:
"\e[1m\e[31mhello\e[0m\e[1m world!\e[0m"
甚至更好(更短):
"\e[1;31mhello\e[0;1m world!\e[0m"
而不是这个:
"\e[1m\e[31mhello\e[0m world!\e[0m"
解决方法
由于没有,我写了自己的,二十一点和妓女聪明一个 –
smart_colored
gem install smart_colored
并运行
require 'smart_colored/extend' # without extend you'll need to use 'string'.colored.red puts "#{'hello'.red} world!".bold