LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-18-2003, 05:21 AM   #1
ankitgdit
LQ Newbie
 
Registered: Aug 2003
Posts: 11

Rep: Reputation: 0
writing bash script


Hai everyone

im writing a shell in c language .I want to know how to handle arrow keys in c language (like in bash by pressing uparrow key we get the last executed command ) and how to refresh the command line prompt (for ex. when we press up arrow key again the penultimate commad appears on the screen erasing the last one ) . If any one knows abt this plz reply as i am in urgent need.

bye


Thanx
 
Old 08-18-2003, 06:44 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
if you are writing a shell...try using the readline library ....it normally comes bundled with the linux installation...
it is the ideal for shells....handles tabs , up and down arrow keys etc...
i think you can even get it at the GNU site in case you cant locate it in your installation CDs
 
Old 08-18-2003, 09:04 AM   #3
ankitgdit
LQ Newbie
 
Registered: Aug 2003
Posts: 11

Original Poster
Rep: Reputation: 0
I wanna know about the c functions to implement these things
and shishir plz be more specific.

thanx
 
Old 08-18-2003, 04:07 PM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
well .. i am sorry but i am sorry cant tell you the exact function calls to do all the key bindings but do an "info readline"...youll find a section that contains the explanations of the functions that can be used for key bindings and a host of other functions provided by the library..sorry cant help you more .. havent used this library ...but remember a project involving its use to build a shell ..a bash like shell..so was more there for troubleshooting while coding than for actual coding
 
Old 08-19-2003, 07:47 AM   #5
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 17
If you want to get events like pressing the cursor keys, you need to do the following:

1. set the terminal/console in raw mode (as opposed to canonical mode, see glibc info pages)
2. read as usual
3. translate the recieved strings. Most non-alphanumerical keys are reported using multi character strings.

Step 3 is the tricky one; every type of terminal has a different way of doing it. You should use terminfo (or termcap) do do the translation, and NEVER EVER hardcode the linux console codes in your program, for the following reasons:

- linux console codes may change one day
- your program may run on an other NIX. Porting Linux to say BSD is almost trivial.
- someone may run your program over rsh/ssh/telnet
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a bash script poiuytrewq Linux - Newbie 2 10-07-2004 11:26 PM
Writing bash script with recursion.. ray5_83 Programming 4 08-04-2004 06:44 PM
Help writing a pinging bash script dehuszar Linux - Software 3 06-18-2004 03:03 PM
Writing to a file - Bash script Skute Programming 2 03-15-2004 05:41 AM
writing a bash/ perl script on debian phr00ta Programming 4 01-29-2004 02:38 PM


All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration