I’m trying to write a shell and I’m at the point where I want to ignore CtrlC.
I currently have my program ignoring SIGINT and printing a new line when the signal comes, but how can I prevent the ^C from being printed?
When pressing CtrlC, here is what I get:
myshell>^C myshell>^C myshell>^C
but I want:
myshell> myshell> myshell>
Here is my code relevant to CtrlC:
extern 'C' void disp( int sig ) { printf('\n'); } main() { sigset( SIGINT, disp ); while(1) { Command::_currentCommand.prompt(); yyparse(); } }
It’s the terminal that does echo that thing. You have to tell it to stop doing that. My manpage of
sttysaysrunning
strace stty ctlechoshowsSo running ioctl with the right parameters could switch that control echo off. Look into
man termiosfor a convenient interface to those. It’s easy to use themAlternatively, you can consider using
GNU readlineto read a line of input. As far as i know, it has options to stop the terminal doing that sort of stuff.