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

问题描述

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

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"

推荐答案

由于没有解决方案,我写了自己的聪明的人- smart_colored

As there is none, I wrote my own, 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

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

06-06 16:24