开发者

Better ruby terminal coloring library

There are plenty of coloring libraries: colored, term-ansicolor. But is there any which can do this:

puts "#{'hello'.red} world!".bold

And world! should be bold.

To make it clear, I want to get this:

"\e[1m\e[31mhello\e[0m\e[1m world!\e[0m"

or better even this (just shorter):

开发者_如何学运维
"\e[1;31mhello\e[0;1m world!\e[0m"

instead of this:

"\e[1m\e[31mhello\e[0m world!\e[0m"


As there is none, I wrote my own, with blackjack and hookers smart one — smart_colored

gem install smart_colored

and run

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

puts "#{'hello'.red} world!".bold


The lib is called Highline It has a color method: say("This should be <%= color('bold', BOLD) %>!") Which can be easily used to implement String#bold.


In case you are using highline I made a gem that extends colors and provides helpers such as:

say_bold 'this is bold text'

https://github.com/bonzofenix/highline-color

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜