1#!/usr/local/bin/ruby
2
3require "curses"
4include Curses
5
6def show_message(*msgs)
7  message = msgs.join
8  width = message.length + 6
9  win = Window.new(5, width,
10		   (lines - 5) / 2, (cols - width) / 2)
11  win.keypad = true
12  win.attron(color_pair(COLOR_RED)){
13    win.box(?|, ?-, ?+)
14  }
15  win.setpos(2, 3)
16  win.addstr(message)
17  win.refresh
18  win.getch
19  win.close
20end
21
22init_screen
23start_color
24init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE)
25init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE)
26crmode
27noecho
28stdscr.keypad(true)
29
30begin
31  mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED)
32  setpos((lines - 5) / 2, (cols - 10) / 2)
33  attron(color_pair(COLOR_BLUE)|A_BOLD){
34    addstr("click")
35  }
36  refresh
37  while( true )
38    c = getch
39    case c
40    when KEY_MOUSE
41      m = getmouse
42      if( m )
43	show_message("getch = #{c.inspect}, ",
44		     "mouse event = #{'0x%x' % m.bstate}, ",
45		     "axis = (#{m.x},#{m.y},#{m.z})")
46      end
47      break
48    end
49  end
50  refresh
51ensure
52  close_screen
53end
54