質問

着色ライブラリがたくさんあります:色付きの用語。しかし、これを行うことができるものはありますか:

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/bonzofenix/highline-color

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top