Class: Fatty::Curses::EventSource

Inherits:
Object
  • Object
show all
Defined in:
lib/fatty/curses/event_source.rb

Constant Summary collapse

MOUSE_BSTATE_BUTTON_MAP =
{
  ::Curses::BUTTON1_PRESSED => :left_pressed,
  ::Curses::BUTTON1_RELEASED => :left_released,
  ::Curses::BUTTON1_CLICKED => :left_clicked,
  ::Curses::BUTTON1_DOUBLE_CLICKED => :left_double_clicked,
  ::Curses::BUTTON1_TRIPLE_CLICKED => :left_triple_clicked,

  ::Curses::BUTTON2_PRESSED => :middle_pressed,
  ::Curses::BUTTON2_RELEASED => :middle_released,
  ::Curses::BUTTON2_CLICKED => :middle_clicked,
  ::Curses::BUTTON2_DOUBLE_CLICKED => :middle_double_clicked,
  ::Curses::BUTTON2_TRIPLE_CLICKED => :middle_triple_clicked,

  ::Curses::BUTTON3_PRESSED => :right_pressed,
  ::Curses::BUTTON3_RELEASED => :right_released,
  ::Curses::BUTTON3_CLICKED => :right_clicked,
  ::Curses::BUTTON3_DOUBLE_CLICKED => :right_double_clicked,
  ::Curses::BUTTON3_TRIPLE_CLICKED => :right_triple_clicked
}.freeze
SCROLL_UP_BSTATE =
::Curses::BUTTON4_PRESSED
SCROLL_DOWN_BSTATE =
0x10000000
MOUSE_MODIFIER_MASK =
::Curses::BUTTON_CTRL |
::Curses::BUTTON_ALT |
::Curses::BUTTON_SHIFT
ESCAPE_LOOKAHEAD_MS =
0
BRACKETED_PASTE_START =
"[200~"
BRACKETED_PASTE_END =
"\e[201~"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context: Context.new, key_decoder: nil, poll_ms: 200) ⇒ EventSource

Returns a new instance of EventSource.



40
41
42
43
44
45
# File 'lib/fatty/curses/event_source.rb', line 40

def initialize(context: Context.new, key_decoder: nil, poll_ms: 200)
  @context = context
  @key_decoder = key_decoder || KeyDecoder.new
  @poll_ms = poll_ms.to_i
  configure_input_polling!
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



38
39
40
# File 'lib/fatty/curses/event_source.rb', line 38

def context
  @context
end

#key_decoderObject (readonly)

Returns the value of attribute key_decoder.



38
39
40
# File 'lib/fatty/curses/event_source.rb', line 38

def key_decoder
  @key_decoder
end

Instance Method Details

#interrupt_pending?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/fatty/curses/event_source.rb', line 51

def interrupt_pending?
  command = read_event(timeout_ms: 0)
  interrupted = interrupt_command?(command)

  pending_events << command if command && !interrupted
  interrupted
end

#next_eventObject



47
48
49
# File 'lib/fatty/curses/event_source.rb', line 47

def next_event
  pending_events.shift || read_event
end