summaryrefslogtreecommitdiff
path: root/sample/curses/mouse.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/curses/mouse.rb')
-rw-r--r--sample/curses/mouse.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/sample/curses/mouse.rb b/sample/curses/mouse.rb
new file mode 100644
index 00000000000..cc4beeb83da
--- /dev/null
+++ b/sample/curses/mouse.rb
@@ -0,0 +1,52 @@
+require "curses"
+
+def show_message(*msgs)
+ message = msgs.join
+ width = message.length + 6
+ win = Curses::Window.new(5, width,
+ (Curses.lines - 5) / 2, (Curses.cols - width) / 2)
+ win.keypad = true
+ win.attron(Curses.color_pair(Curses::COLOR_RED)){
+ win.box(?|, ?-, ?+)
+ }
+ win.setpos(2, 3)
+ win.addstr(message)
+ win.refresh
+ win.getch
+ win.close
+end
+
+Curses.init_screen
+Curses.start_color
+Curses.init_pair(Curses::COLOR_BLUE, Curses::COLOR_BLUE, Curses::COLOR_WHITE)
+Curses.init_pair(Curses::COLOR_RED, Curses::COLOR_RED, Curses::COLOR_WHITE)
+Curses.crmode
+Curses.noecho
+Curses.stdscr.keypad(true)
+
+begin
+ Curses.mousemask(
+ Curses::BUTTON1_CLICKED|Curses::BUTTON2_CLICKED|Curses::BUTTON3_CLICKED|Curses::BUTTON4_CLICKED
+ )
+ Curses.setpos((Curses.lines - 5) / 2, (Curses.cols - 10) / 2)
+ Curses.attron(Curses.color_pair(Curses::COLOR_BLUE)|Curses::A_BOLD){
+ Curses.addstr("click")
+ }
+ Curses.refresh
+ while( true )
+ c = Curses.getch
+ case c
+ when Curses::KEY_MOUSE
+ m = Curses::getmouse
+ if( m )
+ show_message("getch = #{c.inspect}, ",
+ "mouse event = #{'0x%x' % m.bstate}, ",
+ "axis = (#{m.x},#{m.y},#{m.z})")
+ end
+ break
+ end
+ end
+ Curses.refresh
+ensure
+ Curses.close_screen
+end