Class: RubyTerminalGames::Keyboard
- Inherits:
-
Object
- Object
- RubyTerminalGames::Keyboard
- Defined in:
- lib/ruby_terminal_games/keyboard.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
3 4 5 |
# File 'lib/ruby_terminal_games/keyboard.rb', line 3 def thread @thread end |
Class Method Details
.capture(detect_direction: false, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_terminal_games/keyboard.rb', line 5 def self.capture(detect_direction: false, &block) Curses.noecho Curses.stdscr.keypad(true) Curses.curs_set(0) Curses.cbreak Curses.raw @capture_thread = Thread.new do loop do key = Curses.getch command = direction(key) || key command = key unless detect_direction block.call(command) sleep(0.15) end end end |
.stop_capture ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ruby_terminal_games/keyboard.rb', line 23 def self.stop_capture Thread.kill(@capture_thread) Curses.echo Curses.stdscr.keypad(false) Curses.curs_set(1) Curses.crmode Curses.noraw end |