Im trying to Curses.getchr
, but keys like Ctrl+s are not captured, is there any lib that would开发者_JAVA技巧 allow me to capture them and best of all something intuitive/readable like
FooBar.bind('Ctrl+s'){ raise "dont save!" }
Ctrl+s is usually grabbed by the terminal, so you have to put Curses
in raw mode to capture that key. Here is an example:
#!/usr/bin/ruby
require 'curses'
Curses.raw # intercept everything
Curses.noecho
loop do
case Curses.getch
when ?q then break
when ?b then Curses.addch ?b
when ?\C-s then Curses.addstr "^s" # Ctrl+S
end
end
精彩评论