metacran/linenoise-ng

Name: linenoise-ng

Owner: metacran

Description: A small self-contained alternative to readline and libedit that supports UTF-8 and Windows and is BSD licensed.

Created: 2016-01-18 13:40:01.0

Updated: 2016-01-18 13:40:02.0

Pushed: 2016-01-18 14:25:26.0

Homepage:

Size: 192

Language: C++

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Linenoise Next Generation

A small, portable GNU readline replacement for Linux, Windows and MacOS which is capable of handling UTF-8 characters. Unlike GNU readline, which is GPL, this library uses a BSD license and can be used in any kind of program.

Origin

This linenoise implementation is based on the work by Salvatore Sanfilippo and 10gen Inc. The goal is to create a zero-config, BSD licensed, readline replacement usable in Apache2 or BSD licensed programs.

Features

It deviates from Salvatore's original goal to have a minimal readline replacement for the sake of supporting UTF8 and Windows. It deviates from 10gen Inc.'s goal to create a C++ interface to linenoise. This library uses C++ internally, but to the user it provides a pure C interface that is compatible with the original linenoise API. C interface.

Build instructions

Simply include all sources (except for example.cpp) in your project.

Can a line editing library be 20k lines of code?

Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?

So what usually happens is either:

The result is a pollution of binaries without line editing support.

So Salvatore spent more or less two hours doing a reality check resulting in this little library: is it really needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.

Terminals, in 2010.

Apparently almost every terminal you can happen to use today has some kind of support for basic VT100 escape sequences. So Salvatore tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere Salvatore tried to use it, and now can work even on ANSI.SYS compatible terminals, since no VT220 specific sequences are used anymore.

The original library has currently about 4100 lines of code. In order to use it in your project just look at the example.cpp file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.

Tested with…

Please test it everywhere you can and report back!

Let's push this forward!

Patches should be provided in the respect of linenoise sensibility for small and easy to understand code that and the license restrictions. Extensions must be submitted under a BSD license-style. A contributor license is required for contributions.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.