RogueCSDev RogueCSDev - 20 days ago 8
Linux Question

How to detect XOFF and XON in Linux terminal application

Certain control sequences have special effects in Linux, such as

CTRL-C
which sends
SIGINT
. I can handle signals easily enough, but it appears
CTRL-S
(XOFF) and
CTRL-Q
(XON) are special snowflakes. I know their effect (to pause input) can be disabled in the console with
stty -ixon
, and I could use some trickery to run that command, but that feels like a cheap workaround.

Is there a proper way to rid these sequences of their special effect and get their actual ASCII values (
^S
,
^Q
) using system calls? I know it is doable because the text editor Nano does it, but for the life of me I can't find where it's being handled. I already tried searching the repo for "XOFF".

https://github.com/dtrebbien/nano/tree/master/src

Answer

Use the tcgetattr() and tcsetattr() system calls to turn off the IXON flag on standard input, as explained in this manual page.

Comments