Unable to trap C-z, C-y, C-s and C-q

N

Nit Khair

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.
 
N

Nit Khair

Nit said:
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.
 
A

Andrew Lee

Nit said:
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.


You can't catch SIGKILL or SIGSTOP ... has nothing to do with Ruby.
 
R

Ron Fox

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.
Nit said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top