Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-04

Readline substitute

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Johann Glaser

Hi!

I want to equip a program with a command line and therefore want a powerful and user-friendly input prompt. Currently I use

  ReadLn(CmdLine);

which is not as user-friendly as desired. :-)

The usual answer for this question is libreadline. I already worked with it (in plain C) but before I do a header translation for FreePascal I wanted to ask you for your opinion if there is a better alternative or anybody already has a header translation or even programmer-friendly wrapper for the history and auto-completion stuff.

Thanks
Hansi

Johann Glaser
to Johann Glaser

Hi!

Johann Glaser wrote 12 lines
Hi! I want to equip a program with a command line and therefore want a powerful and user-friendly input prompt. Currently I use ReadLn(CmdLine); which is not as user-friendly as desired. :-) The usual answer for this question is libreadline. I already worked with it (in plain C) but before I do a header translation for FreePascal I wanted to ask you for your opinion if there is a better alternative or anybody already has a header translation or even programmer-friendly wrapper for the history and auto-completion stuff.

Ok, I was too impatient and did the header translation now. :-) Please find attached the units Readline and History as well as five example programs. This is compatible to the most current version 6.2 http://tiswww.case.edu/php/chet/readline/rltop.html

Everything is GPL as the GNU Readline Library is itself. I'd be happy if these files can be included in future FreePascal releases.

If you find any improvements or comments don't hesitate to send me an EMail.

Thanks
Hansi

Bernd
to Johann Glaser

2011/5/1 Johann Glaser :

If you find any improvements or comments don't hesitate to send me an EMail.

I just used it. I only needed readline() and add_history(), these two functions are already enough to make a ReadLn() substitute that really works and It works like a charm! Thank you!

I think this code really deserves to be included in FPC.

Unknown author
to Bernd
Show quoted text 10 lines
2011/5/1 Johann Glaser : > If you find any improvements or comments don't hesitate to send me an > EMail. I just used it. I only needed readline() and add_history(), these two functions are already enough to make a ReadLn() substitute that really works and It works like a charm! Thank you! I think this code really deserves to be included in FPC.

Be very careful with ReadLine GPL library. It is not LGPL as far as i know, and therefore it is viral stallmanware... requires we relicense anything else as gpl if you use the library...

See what happened to common lisp clisp when they used it. Had to change license to GPL even though they didn't want to.

Jonas Maebe
to Unknown author
See what happened to common lisp clisp when they used it. Had to change license to GPL even though they didn't want to.

They changed the license because they didn't want to stop using GNU libreadline. If they had switched to a BSD-licensed libreadline, they would not have had to start distributing their code also under a GPL-compatible license.

You may know this, but I think it is important not to spread the false impression that the GPL is like some kind of "virus" that "sticks" to your code once you have been "touched" by it, because that is not that were true, then large parts of the FPC RTL would have been GPL by now since for a while it contained GPL'd code from the FreeCLX.

Jonas

Krishna
to Johann Glaser: Hi! I want to equip a program with a command line and therefore want a powerful and…
Johann Glaser wrote 12 lines
Hi! I want to equip a program with a command line and therefore want a powerful and user-friendly input prompt. Currently I use  ReadLn(CmdLine); which is not as user-friendly as desired. :-) The usual answer for this question is libreadline. I already worked with it (in plain C) but before I do a header translation for FreePascal I wanted to ask you for your opinion if there is a better alternative or anybody already has a header translation or even programmer-friendly wrapper for the history and auto-completion stuff.

linenoise[1] and editline[2] are alternatives. Don't know if there are pascal bindings to those.

[1]: https://github.com/antirez/linenoise
[2]: http://www.thrysoee.dk/editline/

Programming is difficult business. It should never be undertaken in ignorance. --Douglas Crockford, "Javascript: The Good Parts"
Johann Glaser
to Bernd: 2011/5/1 Johann Glaser : I just used it. I only needed readline() and add_history(),…

Hi Bernd!

Bernd wrote 10 lines
2011/5/1 Johann Glaser : > If you find any improvements or comments don't hesitate to send me an > EMail. I just used it. I only needed readline() and add_history(), these two functions are already enough to make a ReadLn() substitute that really works and It works like a charm! Thank you! I think this code really deserves to be included in FPC.

Thanks for your feedback and support!

In the meantime I've added an OOP wrapper which greatly simplifies the usage of the history and readline and helps to implement custom completion.

Please find attached the OOP wrappers and a small example.

I've also used this OOP wrapper for a command line tool which integrates the TCL OOP wrapper (mentioned in this list on 2011-05-05). The completion correctly identifies whether it is asked for commands or variables, and even works inside of the TCL equivalent of backticks. Due to shortage of time it's still a bit messy, but will be released under the terms of the GPL too.

Bye
Hansi

Johann Glaser
to Krishna: linenoise[1] and editline[2] are alternatives. Don't know if there are pascal bindings to…

Hi Krishna!

Krishna wrote 19 lines
On Fri, Apr 29, 2011 at 10:18 PM, Johann Glaser wrote: > Hi! > > I want to equip a program with a command line and therefore want a > powerful and user-friendly input prompt. Currently I use > ReadLn(CmdLine); > which is not as user-friendly as desired. :-) > > The usual answer for this question is libreadline. I already worked with > it (in plain C) but before I do a header translation for FreePascal I > wanted to ask you for your opinion if there is a better alternative or > anybody already has a header translation or even programmer-friendly > wrapper for the history and auto-completion stuff. linenoise[1] and editline[2] are alternatives. Don't know if there are pascal bindings to those. [1]: https://github.com/antirez/linenoise [2]: http://www.thrysoee.dk/editline/

Thanks for the tips!

I've evaluated EditLine but it had drawbacks to GNU Readline. The relatively young linenoise unfortunately doesn't properly support completion.

As mentioned before, I've already settled with GNU readline and already wrote header translations as well as an OOP wrapper. I hope both are useful for somebody and also might be included in future versions of FreePascal.

Thanks
Hansi

Unknown author
to Krishna: linenoise[1] and editline[2] are alternatives. Don't know if there are pascal bindings to…
Show quoted text 11 lines
> The usual answer for this question is libreadline. I already worked with > it (in plain C) but before I do a header translation for FreePascal I > wanted to ask you for your opinion if there is a better alternative or > anybody already has a header translation or even programmer-friendly > wrapper for the history and auto-completion stuff. linenoise[1] and editline[2] are alternatives. Don't know if there are pascal bindings to those. [1]: https://github.com/antirez/linenoise [2]: http://www.thrysoee.dk/editline/

Also these pages too:
http://sourceforge.net/projects/libedit/
http://s11n.net/editline/

All bsd licensed