开发者

ruby curses: How to get ctrl/meta keys with

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜