Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a .Net library similar to GNU readline?

Tags:

c#

.net

readline

I'm considering writing a console application in C# and I want to incorporate history, completion and command line editing features something like GNU readline (but not necessarily as extensive as that!)

Is there an existing library for .net which provides this type of functionality? I guess one option would be to use interop services to call GNU readline. But is there a native option?

like image 667
Paul Moore Avatar asked Jan 07 '10 22:01

Paul Moore


People also ask

How does GNU readline work?

It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.

What is readline support?

7.9 Readline Support Using (ice-9 readline) , you can navigate through the current input line with the cursor keys, retrieve older command lines from the input history and even search through the history entries.

What is a readline version?

Readline is free software, distributed under the terms of the GNU General Public License, version 3. This means that if you want to use Readline in a program that you release or distribute to anyone, the program must be free software and have a GPL-compatible license.


2 Answers

You may want to checkout Miguel de Icaza's getline.cs (the link in the blog post is broken, the code can now be found here). Depending on what features of readline you actually need, it might be enough for your purposes.

The nice thing is, that it is all contained in a single (hence getline.cs) file and MIT X11 licensed.

Using it is pretty easy.

If you want to give it try, just download the file and compile it:

C:\> csc.exe /d:DEMO getline.cs 
C:\> getline.exe
shell>

The #ifdef DEMO part also shows the basic REPL:

var le = new LineEditor("whatever");
string s;

while ((s = le.Edit("my prompt> ", "")) != null)
{
    // User input from command line / prompt now in "s".
}
like image 167
Christian.K Avatar answered Nov 11 '22 18:11

Christian.K


The only thing I know of is Mono-Readline.

It provides a .NET interface to the GNU Readline library - it's a bit raw though, only version 0.0.1, and I've only ever seen it run on the Mono runtime.

You should be careful with licensing too ... AFAIK anything that links the GNU Readline libraries is required to be released under the GPL.

like image 30
Duncan Bayne Avatar answered Nov 11 '22 18:11

Duncan Bayne