ext/curses/mouse.rb


DEFINITIONS

This source file includes following functions.


   1  #!/usr/local/bin/ruby
   2  
   3  require "curses"
   4  include Curses
   5  
   6  def 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
  20  end
  21  
  22  init_screen
  23  start_color
  24  init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE)
  25  init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE)
  26  crmode
  27  noecho
  28  stdscr.keypad(true)
  29  
  30  begin
  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
  51  ensure
  52    close_screen
  53  end