You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No, its not a bug. Ctrl-C is a terminal escape sequence which is (usually) mapped to the special non-printable 'intr' character, represented by the sequence ^C when non-printing characters are force-printed. [See man cat, option -v.] This character typically is used by the shell to send a SIGINT signal. But still, this is a character like any other.
The command you're piping to fish, read foo < /dev/tty, explicitly tells the shell to redirect everything printed to your terminal device to read, and this includes non-printable characters. So when you press Ctrl-C, this character is sent to read just like any other. The read command "reads" a single line— that is, it continues until it encounters either the EOL character (return), or the EOF character, which can be sent with the escape sequence Ctrl-D.
I have to confess I don't understand what's going on. The INTR character does appear on the fd when this redirection is set up, but only if ISIG is unset in the termios. If ISIG is set, which it is by default, it just seems to cancel the current line (i.e. ICANON). It doesn't appear that the signal is being blocked by signal_block(), and it doesn't appear to be delivered to fish. So it's probably being delivered to another signal handler (or otherwise blocked). I need to investigate more.
Is there a better way to get user input through a piped stdin then? Perhaps i'm not using the right tool for my application. By better, i mean a consistent UX with read foo where Ctrl-C interrupts the read process.
Activity
geoff-nixon commentedon Nov 25, 2014
No, its not a bug.
Ctrl-Cis a terminal escape sequence which is (usually) mapped to the special non-printable 'intr' character, represented by the sequence^Cwhen non-printing characters are force-printed. [Seeman cat, option-v.] This character typically is used by the shell to send aSIGINTsignal. But still, this is a character like any other.The command you're piping to fish,
read foo < /dev/tty, explicitly tells the shell to redirect everything printed to your terminal device toread, and this includes non-printable characters. So when you pressCtrl-C, this character is sent toreadjust like any other. Thereadcommand "reads" a single line— that is, it continues until it encounters either theEOLcharacter (return), or theEOFcharacter, which can be sent with the escape sequenceCtrl-D.ridiculousfish commentedon Nov 25, 2014
I have to confess I don't understand what's going on. The INTR character does appear on the fd when this redirection is set up, but only if
ISIGis unset in the termios. If ISIG is set, which it is by default, it just seems to cancel the current line (i.e. ICANON). It doesn't appear that the signal is being blocked bysignal_block(), and it doesn't appear to be delivered to fish. So it's probably being delivered to another signal handler (or otherwise blocked). I need to investigate more.leeola commentedon Nov 25, 2014
@geoff-codes Thanks for the explanation.
Is there a better way to get user input through a piped stdin then? Perhaps i'm not using the right tool for my application. By better, i mean a consistent UX with
read foowhere Ctrl-C interrupts the read process.krader1961 commentedon Mar 23, 2017
This has been fixed in the interim since it was opened.
zanchey commentedon May 17, 2017
Well, it dies with an error message:
Is that the right behaviour here? I think so...