题
有很多着色库:彩色,术语颜色。但是有什么可以做到的:
puts "#{'hello'.red} world!".bold
和 world!
应该大胆。
为了明确说明,我想明白:
"\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
其他提示
lib被称为 高线它有一个 color
方法: say("This should be <%= color('bold', BOLD) %>!")
可以轻松地用于实施 String#bold
.
如果您使用的是高线,我制作了一个延伸颜色的宝石,并提供了诸如:
say_bold 'this is bold text'
不隶属于 StackOverflow