PDA

View Full Version : Coding a shell-like interface



caefer
05-09-2003, 12:57 AM
hi there,
I'm new to the board and rather new to programming for linux as well. but I'm glad I do that now, since it's a lot of fun! ;)

Currently I write some app that is going to use a shell-like interace, where app-internal commands are recognized and executed. To achieve this I did the following (which is no longer a problem, but I thought i let you all know so you maybe have a point on something):

first i wrote some code to read from stdin to a buffer[4096] minding an overrun.
then i wrote a little procedure that checks for known commands and there syntax using the <regex.h>.
if a valid command is given it is then passed to it's execution procedure/function.

and now my problem:
when you push the arrow-keys or any other specialkey, you see it's escapecode on screen and when you then press enter what you read from stdin is totally messed up...
to read from stdin I use getchar().

what I NEED is to eliminate those specialkeys (only way I can think of right now is: read(char) probe(char) buffer(char))
and what I'd LIKE to have is to use at least the arrowkeys to browse an internal command history.

I thought of using gnu history but it is way too powerful for my little concern and it doesn't tell you anything about arrowkeys in the documentation..

:confused: :confused: :confused:
do you know of a save way to do that?
or maybe you know of some free code I could use?

thanks a lot! :rolleyes:

regards
/christian

Hammer
05-09-2003, 05:35 AM
How to read special keys is in here:
http://cboard.cprogramming.com/showthread.php?s=&threadid=34669
(it's at the top of this forum ;) )

vikasgp
05-31-2003, 08:37 AM
I thought of using gnu history but it is way too powerful for my little concern and it doesn't tell you anything about arrowkeys in the documentation


Believe me, it's not. While it may be powerful, no program is small enough not to use it. It's really simple to use, and gives your app a lot of things for free. I added gnu history support to a simple command line tool in an half-hour, without *ever* having used it previously.