Module: RETerm::MouseInput
- Included in:
- NavInput
- Defined in:
- lib/reterm/mixins/mouse_input.rb
Constant Summary collapse
- ALL_EVENTS =
Ncurses::ALL_MOUSE_EVENTS | Ncurses::REPORT_MOUSE_POSITION
- MOUSE_MAP =
{ :PRESSED => :pressed, :RELEASED => :released, :CLICKED => :click, :DOUBLE_CLICKED => :dclick, :TRIPLE_CLICKED => :tclick, }
Instance Method Summary collapse
- #mouse_paste? ⇒ Boolean
-
#on_button(b, evnt, coords) ⇒ Object
May be overridden in subclass, invoked when the user interacts with a button.
- #process_mouse(ch) ⇒ Object
Instance Method Details
#mouse_paste? ⇒ Boolean
14 15 16 |
# File 'lib/reterm/mixins/mouse_input.rb', line 14 def mouse_paste? !!reterm_opts[:mouse_paste] end |
#on_button(b, evnt, coords) ⇒ Object
May be overridden in subclass, invoked when the user interacts with a button.
24 25 26 |
# File 'lib/reterm/mixins/mouse_input.rb', line 24 def (b, evnt, coords) #puts "B#{b} #{evnt}, #{coords}" end |
#process_mouse(ch) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/reterm/mixins/mouse_input.rb', line 28 def process_mouse(ch) return nil unless ch == Ncurses::KEY_MOUSE mev = Ncurses::MEVENT.new Ncurses.getmouse(mev) if mev.bstate == Ncurses::BUTTON2_CLICKED && mouse_paste? # TODO grab clipboard buffer & return character array # (need to handle seperately in invoker) # # use https://github.com/janlelis/clipboard # but note this requires external programs! end # TODO 5 button support (requiest "--enable-ext-mouse" ncurses flag # which is not specified in many major distrubtions) 1.upto(4).each { |b| MOUSE_MAP.each { |n, e| if mev.bstate == Ncurses.const_get("BUTTON#{b}_#{n}") x,y,z = mev.x, mev.y, mev.z (b, e, [x,y,z]) end } } # TODO wrap MEVENT w/ our own class, # w/ high levels helpers for buttons, coords, etc mev end |