Class: Fatty::Curses::EventSource
- Inherits:
-
Object
- Object
- Fatty::Curses::EventSource
- 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
- ESCAPE_LOOKAHEAD_MS =
0- BRACKETED_PASTE_START =
"[200~"- BRACKETED_PASTE_END =
"\e[201~"
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#key_decoder ⇒ Object
readonly
Returns the value of attribute key_decoder.
Instance Method Summary collapse
-
#initialize(context:, key_decoder:, poll_ms: 200) ⇒ EventSource
constructor
A new instance of EventSource.
- #next_event ⇒ Object
Constructor Details
#initialize(context:, key_decoder:, poll_ms: 200) ⇒ EventSource
Returns a new instance of EventSource.
33 34 35 36 37 38 |
# File 'lib/fatty/curses/event_source.rb', line 33 def initialize(context:, key_decoder:, poll_ms: 200) @context = context @key_decoder = key_decoder @poll_ms = poll_ms.to_i configure_input_polling! end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
31 32 33 |
# File 'lib/fatty/curses/event_source.rb', line 31 def context @context end |
#key_decoder ⇒ Object (readonly)
Returns the value of attribute key_decoder.
31 32 33 |
# File 'lib/fatty/curses/event_source.rb', line 31 def key_decoder @key_decoder end |
Instance Method Details
#next_event ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fatty/curses/event_source.rb', line 40 def next_event raw = read_raw return unless raw if raw.is_a?(Fatty::MouseEvent) return [:key, raw] end if raw.is_a?(Array) && raw.first == :paste return [:cmd, :paste, { text: raw.last }] end ev = @key_decoder.decode(raw) return unless ev [:key, ev] end |