diff options
author | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-12 23:42:44 +0000 |
---|---|---|
committer | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-12 23:42:44 +0000 |
commit | 9eded5fa137fc0d25c1096890a706c4437043227 (patch) | |
tree | 72bbbd6461756d8615183a7a56f21620b29e8c19 /ext/curses/mouse.rb | |
parent | 7e97ab23f81b94b93dca9fec9ea8997c46a59e11 (diff) |
new methods and constants for using the mouse, character attributes,
colors and key codes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/curses/mouse.rb')
-rw-r--r-- | ext/curses/mouse.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ext/curses/mouse.rb b/ext/curses/mouse.rb new file mode 100644 index 0000000000..c42bc31f33 --- /dev/null +++ b/ext/curses/mouse.rb @@ -0,0 +1,53 @@ +#!/usr/local/bin/ruby + +require "curses" +include Curses + +def show_message(*msgs) + message = msgs.join + width = message.length + 6 + win = Window.new(5, width, + (lines - 5) / 2, (cols - width) / 2) + win.keypad = true + win.attron(color_pair(COLOR_RED)){ + win.box(?|, ?-, ?+) + } + win.setpos(2, 3) + win.addstr(message) + win.refresh + win.getch + win.close +end + +init_screen +start_color +init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE) +init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE) +crmode +noecho +stdscr.keypad(true) + +begin + mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED) + setpos((lines - 5) / 2, (cols - 10) / 2) + attron(color_pair(COLOR_BLUE)|A_BOLD){ + addstr("click") + } + refresh + while( true ) + c = getch + case c + when KEY_MOUSE + m = 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 + refresh +ensure + close_screen +end |