1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/sample/curses/mouse.rb
zzak ffb9da9fa0 * ext/curses/curses.c: [DOC] Update location of samples
* samples/curses/*: Move Curses samples and refactor from mixin
  The samples are included in rdoc for module and use of mixin is
  confusing


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 13:25:46 +00:00

52 lines
1.3 KiB
Ruby

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