LoginSignup
39
39

More than 5 years have passed since last update.

ターミナルで使える色と色番号を一覧にする

Posted at

vim の colorscheme をカスタマイズするのに色番号一覧が欲しいなと思いました。
さらに iTerm2 の Color 設定が反映されている状態の色を知りたかったので、まるっきりこちらのブログの記事を参考にターミナル上で色一覧を生成。

Ruby で書きました。

termcolor.rb
# -*- coding: utf-8 -*-

@fg = "\x1b[38;5;"
@bg = "\x1b[48;5;"
@rs = "\x1b[0m"

def color(code)
  number = '%3d' % code
  "#{@bg}#{code}m #{number}#{@rs}#{@fg}#{code}m #{number}#{@rs} "
end

256.times do |n|
  print color(n)
  print "\n" if (n + 1).modulo(8).zero?
end
print "\n"

実行するとこんな感じ。

実行例

39
39
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
39
39