Sha256: 7f38db6864af990b100fa05acc8bcd017d18609a07ae8f0d96160783d98fa32f

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'vedeu/support/terminal'
require 'vedeu'

module Vedeu
  class Input
    def self.capture
      new.capture
    end

    def capture
      Vedeu.trigger(:_keypress_, keypress)
    end

    private

    def input
      @_input ||= Terminal.input
    end

    def keypress
      key        = input
      translated = case key
      when "\r"      then :enter
      when "\t"      then :tab
      when "\e"      then :escape
      when "\e[A"    then :up
      when "\e[B"    then :down
      when "\e[C"    then :right
      when "\e[D"    then :left
      when "\e[5~"   then :page_up
      when "\e[6~"   then :page_down
      when "\e[H"    then :home
      when "\e[3~"   then :delete
      when "\e[F"    then :end
      when "\eOP"    then :f1
      when "\eOQ"    then :f2
      when "\eOR"    then :f3
      when "\eOS"    then :f4
      when "\e[15~"  then :f5
      when "\e[17~"  then :f6
      when "\e[18~"  then :f7
      when "\e[19~"  then :f8
      when "\e[20~"  then :f9
      when "\e[21~"  then :f10
      when "\e[23~"  then :f11
      when "\e[24~"  then :f12
      when "\e[1;2P" then :print_screen
      when "\e[1;2Q" then :scroll_lock
      when "\e[1;2R" then :pause_break
      when "\u007F"  then :backspace
      else
        key
      end

      translated
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.1.0 lib/vedeu/support/input.rb
vedeu-0.0.42 lib/vedeu/support/input.rb
vedeu-0.0.41 lib/vedeu/support/input.rb
vedeu-0.0.40 lib/vedeu/support/input.rb