Domanda

Nel tentativo di Curses.getchr, ma tasti come Ctrl + s non vengono catturati, c'è qualche lib che mi permettesse di catturarli e meglio di tutti qualcosa di intuitivo / leggibile come

FooBar.bind('Ctrl+s'){ raise "dont save!" }
È stato utile?

Soluzione

Ctrl + s è di solito afferrato dal terminale, quindi bisogna mettere Curses in modalità raw alla cattura quella chiave. Ecco un esempio:

#!/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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top