有很多着色库:彩色,术语颜色。但是有什么可以做到的:

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'

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top