Module: Flippy::Console

Defined in:
lib/flippy/console.rb

Overview

On your terminal, try ‘flippy -c` then type normally. <ESC> key to exit. ^R, ^G, ^B, ^E are for setting color. ^F is for flush screen.

Class Method Summary collapse

Class Method Details

.runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flippy/console.rb', line 11

def run
  buffer = ""
  terminal do
    clear
    move_to_top
    while chr = $stdin.getc
      clear
      case chr
      when escape_key?
        exit
      when back_key?
        buffer.chop!
      when *%w(R G B).map { |ch| ctr_with ch }
        set_color(chr)
      when ctr_with('E')
        reset_color
      when ctr_with('F')
        buffer.clear
      else
        buffer << chr
      end
      flipped = buffer.flip
      print flipped
      reset_cursor(flipped)
    end
  end
end