更好的红宝石终端着色库 [英] Better ruby terminal coloring library

查看:111
本文介绍了更好的红宝石终端着色库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多着色库:有色,术语-反色. 但是,有什么可以做到的:

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

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

并且world!应该为粗体.

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

To make it clear, I want to get this:

"\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"

推荐答案

由于没有解决方案,我写了自己的酒杯和妓女聪明的人-

As there is none, I wrote my own, with blackjack and hookers smart one — 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

这篇关于更好的红宝石终端着色库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆