Miniedit

Miniedit is a command line editor library providing generic text entry capabilities. Specifically, miniedit implements this function:

wchar_t *editline(const wchar_t *prompt);

editline() will print prompt, read one line of text from user and return it, without the final newline, in a string allocated by malloc().

You can brose miniedit sources at [1] or grab them via Mercurial like this:

hg clone http://hg.tx97.net/miniedit

Features

An example

Here's the simplest example:

/* example.c */
#include "miniedit.h"
#include <locale.h>
#include <stdio.h>
int main() {
    setlocale(LC_CTYPE, "");
    wchar_t *name = editline(L"Type in your name, friend: ");
    if (name) {
        wprintf(L"Hello and welcome, %ls!\n", name);
        free(name);
    } else {
        wprintf(L"Bonsoir, stranger!\n");
    }
    return 0;
}

Note several things:

How to build it

To compile the example above for a Unix, you'll need a C99 compiler and termcap library. On *BSD all the needed termcap files come with the system; on a Debian-based system you'll need to install libncurses5-dev package first. Once you've done that, you can build the above example like this:

cc -std=c99 -o example example.c miniedit.c -ltermcap

To compile it for Windows, you'll only need a C99 compiler. For example, if you have a MinGW toolset installed, you could do it this way:

i686-pc-mingw32-gcc -std=c99 -o example.exe example.c miniedit.c 

Similar software

There are multiple libraries that cover the functionality of miniedit. GNU readline [2] and libedit [3] are the most widely used of them. Miniedit was developed as a response to those two libraries being way too big and lacking Windows support.

References

  1. http://hg.tx97.net/miniedit
  2. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
  3. http://thrysoee.dk/editline/