更好的红宝石终端着色库

tig*_*tig 4 ruby terminal ansi-colors

有很多着色库:彩色,term-ansicolor.但有没有可以做到这一点:

puts "#{'hello'.red} world!".bold
Run Code Online (Sandbox Code Playgroud)

而且world!应该大胆.

为了说清楚,我想得到这个:

"\e[1m\e[31mhello\e[0m\e[1m world!\e[0m"
Run Code Online (Sandbox Code Playgroud)

甚至更好(更短):

"\e[1;31mhello\e[0;1m world!\e[0m"
Run Code Online (Sandbox Code Playgroud)

而不是这个:

"\e[1m\e[31mhello\e[0m world!\e[0m"
Run Code Online (Sandbox Code Playgroud)

tig*_*tig 8

由于没有,我写了自己的,二十一点和妓女聪明一个 - smart_colored

gem install smart_colored
Run Code Online (Sandbox Code Playgroud)

并运行

require 'smart_colored/extend'
# without extend you'll need to use 'string'.colored.red

puts "#{'hello'.red} world!".bold
Run Code Online (Sandbox Code Playgroud)