Forum: Ruby Unable to trap C-z, C-y, C-s and C-q

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2008-10-13 20:04
I need to trap ^Y, ^Z, ^S, ^Q etc in my app. Have googled a lot but
unable to find anything.

Finally, I wrote a program and trapped all the signals.

1. Both C-z and C-y are trapped by SIGTSTP, but there is no key in
getch() that they seem to trigger. Regardless of whether I use "SIG_IGN"
or print, my curses program aborts.


2. I am still not getting C-s and C-q. They are not caught by any
signal.

My code inside a ncurses program is like this:

%w[ TSTP CONT ABRT HUP STOP PIPE IO IOT CHLD CLD ILL INFO QUIT SYS TRAP
TTOU  URG USR1 USR2 ].each { | alrm |
  #Signal.trap("SIG#{alrm}") { stdscr.mvprintw(17, 2, "%-40s" % "#{alrm}
");

 stdscr.refresh; }        Signal.trap("SIG#{alrm}") { "SIG_IGN" }

}

The commented line prints TSTP for both C-y and c-z and exits.
The second exits.

Its not a terminal setting since I use Vim and alpine and they use these
keys.
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2008-10-13 21:17
Nit Khair wrote:
> I need to trap ^Y, ^Z, ^S, ^Q etc in my app. Have googled a lot but
> unable to find anything.
>

I finally found a workaround.
On unix prompt did:

stty dsusp undef
stty susp undef

Now my program catches c-y and c-z. However, is there are pure ruby way
of doing this. googling reveals examples where "system stty ..." is
being used.
24adb81b629ec102367aa40b4b90743b?d=identicon&s=25 Andrew Lee (Guest)
on 2008-10-14 00:25
(Received via mailing list)
Nit Khair wrote:
>
> Now my program catches c-y and c-z. However, is there are pure ruby way
> of doing this. googling reveals examples where "system stty ..." is
> being used.


You can't catch SIGKILL or SIGSTOP ... has nothing to do with Ruby.
F6a834b9e424a1e5b199db450462b6cd?d=identicon&s=25 Ron Fox (Guest)
on 2008-10-14 13:25
(Received via mailing list)
probbably best to set the terminal to raw mode if this is unix as I
suspect. http://www.rubyquiz.com/quiz5.html
shows an example of this.  Search for the read_char method or just
for the string 'raw'.

Ron.
0026dd77fd9ecc97b36e5b79cdbcf590?d=identicon&s=25 R. Kumar (sentinel)
on 2008-10-14 13:39
Ron Fox wrote:
> probbably best to set the terminal to raw mode if this is unix as I
> suspect. http://www.rubyquiz.com/quiz5.html
> shows an example of this.  Search for the read_char method or just
> for the string 'raw'.
>
> Ron.

Thanks to your tip, I just checked curses.raw(), and *there* it is !!!
Just what I needed.
------
curses.raw()
    Enter raw mode. In raw mode, normal line buffering and processing of
interrupt, quit, suspend, and flow control keys are turned off;
characters are presented to curses input functions one by one.
------
This topic is locked and can not be replied to.