LoginSignup
4
0

More than 5 years have passed since last update.

Thorで出力テキストに色をつける

Posted at

Thorで出力テキストに色をつけます

Thorとは?

Ruby の CLI ツールの作成を支援するライブラリです。

Ruby の CLI ツールの作成を支援する、 thor gem の基本について - Qiita

サンプル

コード

sample.rb
require 'thor'

def error_message(message)
  colored_message(message, ::Thor::Shell::Color::RED)
end

def warning_message(message)
  colored_message(message, ::Thor::Shell::Color::YELLOW)
end

def colored_message(message, color)
  ::Thor::Shell::Color.new.set_color(message, color)
end

puts error_message("エラーだお")
puts warning_message("ワーニングーだお")

出力

$ ruby sample.rb
エラーだお
ワーニングーだお

outputs.png

関連資料

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0