Question

I'm trying to build my own console and I'm using the below statement to get RAW access so I can implement some advanced features such as implementing the auto suggest feature that's implemented in a BASH shell by pressing the TAB key.

system("/bin/stty raw")

When using this, the enter key (and others) doesn't behave normally and when I press enter, it displays ^M and doesn't go to the next line.

  1. How do I set the RAW console to go to the next line when it receives ^M

  2. Also can I set the Shell to NOT display the keys pressed so I can send the char back to the console with putchar() (so ^M doesn't display when pressed).

Thanks

Was it helpful?

Solution

How do I set the RAW console to go to the next line when it receives ^M

You write an appropriate control code to the console when you read an ^M. The whole point of raw mode is that the console does not do things like recognize line ends, backspaces, etc., etc., because you want to handle them yourself. Once you do that, you need to handle all those things.

can I set the Shell to NOT display the keys pressed

Sure. Turn off echo. With the stty command, you would use stty raw -echo but if you're doing this from a C program, you'd be much better off using the terminal API. See man tcsetattr

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top