#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'io/console'
require 'io/console/size'

#画面を消去して、真ん中に移動しておく
print "\e[2J"
iro=["白","赤","緑","黃","青","マゼンタ","シアン"]
a=0
print("色:#{iro[a]}")
print "\e[%d;%dH" % IO::console_size.map{|size| size / 2 }

while (key = STDIN.getch) != "\C-c"
  if key == "\e" && STDIN.getch == "["
    key = STDIN.getch
  end

  # 方向を判断
  direction = case key
  when "A", "w", "\u0017"; "A" #↑ \C-w
  when "B", "s", "\u0013"; "B" #↓ \C-s
  when "C", "d", "\u0004"; "C" #→ \C-d
  when "D", "a", "\u0001"; "D" #← \C-a
  else nil
  end
  # カーソル移動
  print "\e[#{direction}" if direction
  if key=="\u0017"||key=="\u0013"||key=="\u0004"||key=="\u0001"
  print("@")
  print("\e[1D")
  end
end
