small "readline" routine?

Jan 07, 2004 9 Replies

I need to add a simple command-line interface to an embedded project. Has anybody run across a small, free, readline-like library that provides rudimentary command-line editing?


-- Grant Edwards grante Yow! BRILL CREAM is at CREAM O' WHEAT in another visi.com DIMENSION...


On 07 Jan 2004 22:20:34 GMT, Grant Edwards wrote in comp.arch.embedded:

I think your question is a little too vague, but if you provide more detail you can probably find something you can use.

What processor, language, compiler, communications interface? How much RAM and code space are available? Do you just want a line input/editor or text parser as well? What does your command line interface look like? What sort of editing features?

Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

Actually I believe that writing such routine would take less time than searching for it and adopting it to your project. The whole stuff (with backspace and line length limit handling) takes less than 20 lines of C code and approx. 35 lines of 51 assembly.

I heard gdb has a general purpose routine like that. I usually write my own, it takes about

2 or 3 pages if you make it full featured (arrow editing, insert/overwrite mode, word forward, word back, history recall, etc).

I allways thought it was facinating that you can write such a routine with just backspace as the only control character used to manipulate the screen. Cursor forward is done by outputting the character at the position.

"Grzegorz Mazur" wrote in news:btj3ds$2mjq$ snipped-for-privacy@mamut.aster.pl:

I'm thinking of the bash shell command line editing capabilities and wondering how that could possibly be about 20 lines of C. I'd like to see this implementation of yours.

- Mark -> --

H8

C

GCC 3.3

Assume raw putc()/getc() type routines are available and they're connected to an ANSI terminal.

A total of maybe 8-16K for this function.

Yes.

No.

Undefined.

Most important: * recall the last few lines * move forward/reverse a character at a time * delete and backspace * insert typed characters at cursor Nice to have: * move to beginning/end of line * move forward backward word at a time * delete to end of line * delete word * transpose two characters at cursor Hardwired (but configurable in source code) keybindings are fine (my fingers speak emacs).

Grant Edwards grante Yow! I just got my PRINCE at bumper sticker... But now I visi.com can't remember WHO he is...

Me too. Specifically, I was thinking of a subset of Gnu "readline" (I guess I should have been more specific).

I don't need full-up Gnu readline with vi and emacs modes, but I would like command history, move by character/word delete character word, start of line, end of line. Don't need kill/yank or multiple modes and keybindings.

Grant Edwards grante Yow! Someone is DROOLING at on my collar!! visi.com

I had assumed it used the Gnu readline library (which is a bit heavyweight for a small embedded system).

Yea, me too. I thought maybe I'd look for a pre-existing one this time.

At low baud rates that method can be interesting to watch...

Grant Edwards grante Yow! Go on, EMOTE! I at was RAISED on thought visi.com balloons!!

Grant Edwards wrote in news:3ffd6f17$0$959$ snipped-for-privacy@newsreader.visi.com:

Me too!

- Mark -> --

Oops, didn't notice the 'redline' keyword. Single-line editing was what I meant. Of course if you are looking for history buffer etc., it's probably better to start with some Linux/Unix shell source then to write it from scratch..

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required