• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

terminal keeps screwing up when coding

Red Squirrel

No Lifer
At random when I'm coding and I exit my program that I'm working on, the terminal totally screws up. When I hit enter instead of actually doing a return it just repeats the prompt on the same line. If I try to type anything it does not show up, but does register since if I type a command it takes it.

This is VERY irritating as I have to keep rebooting my server. Is there a way to stop this? A program should not affect the terminal permanently after it's been exited so this is a serious bug in bash.
 
can you give an example of what causes this? bash is generally pretty stable, so for you to have found a whole new case which causes problems is unlikely, though I guess it is possible.
 
It could be that your program is printing some nasty control characters to the terminal -- that happens to me sometimes when I have an overrun on a printf() or something. The only way I know to fix it is to use a new terminal -- but you say it requires a reboot to fix...?
 
what editor are you using? is the executable you're running at the command line? Is it outputting unfriendly characters?

usually typing in "reset" or "stty echo" will fix the terminal problems you're experiencing.
 
It seems to happen when I ctrl+c out of my app. The app was to test multithreading and was just outputting a bunch of 0's and 1's and braces. Reset would not work either, but I did not try the stty echo so I'll try that next time it happens.
 
A program should not affect the terminal permanently after it's been exited so this is a serious bug in bash.

It has nothing to do with bash, it's the terminal that's got the problem and even then it's not really a problem with the terminal. AFAIK nothing guarantees that any terminal will keep and restore state across process invocations.

If reset doesn't fix it the only solution I know of is to open a new terminal.
 
It happened again. stty echo seems to have fixed it. I'll be sure to save that one as it may be handy!

Seems to happen when I ctrl+c out of a "press any key to continue"
 
Found the issue. It was if I CTRL+C out of this code:

unsigned int GetChar()
{
#ifdef WIN32
return getch();
#endif
#ifdef linux
int ch;
struct termios oldt, newt;
tcgetattr ( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
return ch;
#endif
}



If I remove the ECHO flag it seems to fix it. Thought I'd post this if ever someone runs into the same issue.

Only problem is this makes the program echo keys...
 
If you're going to use that for "Press any key to continue" you better put a signal handler in for SIGINT to restore the state of the terminal.

Alternatively you could just get rid of all that crazy tcsetattr stuff and just do getchar 😉
 
Back
Top