开发者

ruby curses: How to get ctrl/meta keys with

开发者 https://www.devze.com 2023-02-02 22:11 出处:网络
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

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

精彩评论

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