1

Im trying to Curses.getchr, but keys like Ctrl+s are not captured, is there any lib that would allow me to capture them and best of all something intuitive/readable like

FooBar.bind('Ctrl+s'){ raise "dont save!" }
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
grosser
  • 14,707
  • 7
  • 57
  • 61

1 Answers1

3

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
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
cam
  • 14,192
  • 1
  • 44
  • 29