Thread: Coding a shell-like interface

  1. #1
    Registered User
    Join Date
    May 2003

    Question Coding a shell-like interface

    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..

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

    thanks a lot!


  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    How to read special keys is in here:
    (it's at the top of this forum )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    May 2003
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is the best interface coding
    By ExDHaos in forum C++ Programming
    Replies: 2
    Last Post: 05-18-2009, 02:36 AM
  2. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  3. What shell is more powerful?
    By xddxogm3 in forum Tech Board
    Replies: 10
    Last Post: 07-24-2004, 10:47 PM
  4. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM
  5. simple shell coding
    By estranged in forum C Programming
    Replies: 6
    Last Post: 09-30-2002, 05:59 AM