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

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

  • single-line and multi-line editing mode with the usual key bindings implemented
  • history handling
  • completion
  • BSD license source code
  • Only uses a subset of VT100 escapes (ANSI.SYS compatible)
  • UTF8 aware
  • support for Linux, MacOS and Windows

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.

Requirements

To build this library, you will need a C++11-enabled compiler and some recent version of CMake.

Build instructions

To build this library on Linux, first create a build directory

mkdir -p build

and then build the library:

(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make)

To build and install the library at the default target location, use

(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && sudo make install)

The default installation location can be adjusted by setting the DESTDIR variable when invoking make install:

(cd build && make DESTDIR=/tmp install)

To build the library on Windows, use these commands in an MS-DOS command prompt:

md build
cd build

After that, invoke the appropriate command to create the files for your target environment:

  • 32 bit: cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..
  • 64 bit: cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_BUILD_TYPE=Release ..

After that, open the generated file linenoise.sln from the build subdirectory with Visual Studio.

note: the following sections of the README.md are from the original linenoise repository and are partly outdated

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:

  • Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).

  • Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).

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 1100 lines of code. In order to use it in your project just look at the example.c 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...

  • Linux text only console ($TERM = linux)
  • Linux KDE terminal application ($TERM = xterm)
  • Linux xterm ($TERM = xterm)
  • Linux Buildroot ($TERM = vt100)
  • Mac OS X iTerm ($TERM = xterm)
  • Mac OS X default Terminal.app ($TERM = xterm)
  • OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
  • IBM AIX 6.1
  • FreeBSD xterm ($TERM = xterm)
  • ANSI.SYS
  • Emacs comint mode ($TERM = dumb)
  • Windows

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.

Owner
ArangoDB
the multi-model NoSQL database
ArangoDB
Comments
  • Add syntax highlighting capabilities.

    Add syntax highlighting capabilities.

    I would like to know your opinion about extending linenoise-ng with ability to colorize user input on the fly.

    Proposed changes to the API:

    typedef int color_t;
    typedef void (linenoiseColorizationCallback)(char const* input, color_t* colors, int size);
    void linenoiseSetColorizationCallback(linenoiseColorizationCallback* fn);
    

    Where: input is current input colors is buffer for requested colors size is size of both user input in characters and colors buffer.

    How would it work. If user want to have colorful input she must simply install "colorization handler". The handler would be invoked by the library after each change to the input done by the user. After handler returns library uses data from colors buffer to colorize displayed user input.

    Should I code such addition to linenoise-ng?

    [Edit] I have implemented this feature, and here is how it looks like: demo [/Edit]

  • Can it used for arm64?

    Can it used for arm64?

    i need it for interactive cli on arm. but it compile errors. such as

    λ : make do FINALPACKAGE=1> Making all for tool dumpRuntimeMacho…
    ==> Compiling lib/linenoise/linenoise.cpp (arm64)…
    lib/linenoise/linenoise.cpp:133:12: error: no member named 'unique_ptr' in namespace 'std'
    using std::unique_ptr;
          ~~~~~^
    lib/linenoise/linenoise.cpp:422:3: error: use of undeclared identifier 'unique_ptr'
      unique_ptr<char[]> text8(new char[len8]);
      ^
    lib/linenoise/linenoise.cpp:422:18: error: expected '(' for function-style cast or type construction
      unique_ptr<char[]> text8(new char[len8]);
                 ~~~~^
    lib/linenoise/linenoise.cpp:425:19: error: use of undeclared identifier 'text8'
      copyString32to8(text8.get(), len8, &count8, text32, len32);
                      ^
    lib/linenoise/linenoise.cpp:427:20: error: use of undeclared identifier 'text8'
      return write(fd, text8.get(), count8);
    

    thank you.

  • Update linenoise.cpp

    Update linenoise.cpp

    I ran into trouble when trying to compile this under mingw64 (if you really want to know, I was compiling with rust-linenoise).

    Basically, _snprintf was redefined and that caused an error. Now I'm able to compile...

  • Make installing conditional.

    Make installing conditional.

    This allows the user to specify if linenoise should be installed at cmake configuration time. Defaults to ON, i.e. no functional change.

    Being able to disable installation is useful when linenoise is used as a sub-project.

  • Port of linenoise/antirez#104

    Port of linenoise/antirez#104

    Hello,

    This is a simple port of https://github.com/antirez/linenoise/pull/104/files . It adds a method to access the history.

    This PR comes in order to be able to use linenoise-ng in my FFI binding rust-linenoise and preserve:

    • the current API in my binding
    • the contribution of @sprowell in my binding.

    (the PR has also cleaned up some extra space, let me know if you want me to remove these changes from the PR).

  • history file permissions

    history file permissions

    Is it worth applying this fix from antirez/linenoise? The change forces the history file to have mode 600 so it remains private. See the patch here.

    https://github.com/antirez/linenoise/commit/c894b9e59f02203dbe4e2be657572cf88c4230c3#diff-72af1757e65272a44fc4aa3b479e2f3b

    It may be useful to consider other code changes introduced after the fork.

  • History file permissions broken on POSIX/Linux

    History file permissions broken on POSIX/Linux

    Hi, I noticed some really strange permissions on my history file of '-rw---S--T' and believe that the fix in commit 8e09e9293d666741e79bb5ecb9942ca4e652944e is incorrect. The permissions passed to open() directly apply to the file, and as such passing ~(S_IXUSR | S_IRWXG | S_IRWXO) which is the negation of all the permissions you don't want, sure turns those off, but also flips all other bits to 1, which results in the observed broken behavior. man open(2) says "According to POSIX, the effect when other bits are set in mode is unspecified. On Linux, the following bits are also honored in mode: S_ISUID, S_ISGID, S_ISVTX". Unspecified is bad, and on Linux it turns on the set-uid/set-gid and sticky bits, which is not what you want at all. Just passing (S_IRUSR | S_IWUSR) is all you need for open(), that way only the two permissions you do really want (user read and write) are turned on, the rest remains off.

  • Version bump to 1.0.1

    Version bump to 1.0.1

    It would be awesome if you could tag a 1.0.1 release in Github. I could bump downstream packages in Choco/Brew/etc to pull in the recent changes since 1.0.0. :)

  • compiling with MinGW - problem and solution

    compiling with MinGW - problem and solution

    Compiling under MinGW on Windows 10 (64-bit), produces an error.

        _stricmp was not declared in this scope
    

    This change fixes it.

    -> #if !defined GNUC #define strcasecmp _stricmp -> #enfif

  • Building liblinenoise.so

    Building liblinenoise.so

    I am sure I built the shared object yesterday by just following the build instructions (viz. (cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && sudo make install)) , but I cannot repeat that achievement today. :-( All that gets built and installed today are the .a and .h files. What I am doing wrong?

  • Bug fixes

    Bug fixes

    Three small fixes:

    1. FreeBSD open() does not have S_IRUSR | S_IWUSR
    2. The source pointer for memcpy() in linenoiseHistorySave() is incorrect. It should point to head of list.
    3. linenoiseHistorySave() needs to check for NULL pointer (although this was a side effect of (2))
  • ConvertUTF.{cpp,h} are non-free

    ConvertUTF.{cpp,h} are non-free

    The ConvertUTF.{cpp,h} are non-free (and buggy/unmaintained), as discussed on the Debian mailing list:

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=823100

    This poses problems for packaging/redistribution. Would it be possible to, perhaps, support linking with libicu for this purpose?

    We're currently using linenoise-ng in Nix, and this issue is blocking an effort to package Nix for Debian. We could always fork linenoise-ng to use libicu, but considering that all software using linenoise-ng right now are built with non-free code, I figure it makes most sense to have this resolved here.

    Thanks!

Related tags
A small self-contained alternative to readline and libedit

Linenoise A minimal, zero-config, BSD licensed, readline replacement used in Redis, MongoDB, and Android. Single and multi line editing mode with the

Sep 27, 2022
crypted admin shell: SSH-like strong crypto remote admin shell for Linux, BSD, Android, Solaris and OSX
crypted admin shell: SSH-like strong crypto remote admin shell for Linux, BSD, Android, Solaris and OSX

crypted admin shell: SSH-like strong crypto remote admin shell for Linux, BSD, Android, Solaris and OSX

Aug 25, 2022
Alternative firmware for IP cameras based on the HiSilicon (and other) SoC's
Alternative firmware for IP cameras based on the HiSilicon (and other) SoC's

OpenIPC v2.1 (experimental, buildroot based..) Alternative firmware for IP cameras based on the HiSilicon (and other) SoC's More information about the

Sep 27, 2022
Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.

Oct 1, 2022
The new Windows Terminal and the original Windows console host, all in the same place!

The new Windows Terminal and the original Windows console host, all in the same place!

Sep 28, 2022
A (relatively) small node library to clone and pull git repositories in a standalone manner thanks to libgit2, powered by WebAssembly and Emscripten

simple-git-wasm A (relatively) small node library to clone and pull git repositories in a standalone manner thanks to libgit2, powered by WebAssembly

May 20, 2022
Small header only C++ library for writing multiplatform terminal applications

Terminal Terminal is small header only library for writing terminal applications. It works on Linux, macOS and Windows (in the native cmd.exe console)

Sep 22, 2022
cpp-progressbar is a small console program I wrote in c++. 3 themes are available
cpp-progressbar is a small console program I wrote in c++. 3 themes are available

cpp-progressbar cpp-progressbar is a small console program I wrote in c++. 3 themes are available (this program only works on linux) Instalation Downl

Jun 17, 2022
Minimal but open SDK for developing small command line tools.

Minimal SDK for macOS This repository provides the basis to build a cross compiler for macOS. With it, you can compile small command line tools from a

Mar 18, 2022
Free open-source modern C++17 / C++20 framework to create console, forms (GUI like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.
Free open-source modern C++17 / C++20 framework to create console, forms (GUI like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.

xtd Modern C++17/20 framework to create console (CLI), forms (GUI like WinForms) and tunit (unit tests like Microsoft Unit Testing Framework) applicat

Sep 25, 2022
Traffic capture and intercept program based on Windows Filtering Platform (WFT)

Traffic capture and intercept program based on Windows Filtering Platform (WFT)

Oct 17, 2021
A Windows Shell Extension for the Pixar USD file format.

Activision USD Shell Extension A Windows Shell Extension for the Pixar USD file format. Windows Explorer Features Hydra Realtime Preview Thumbnails Co

Sep 25, 2022
Windows command line program for Spleeter, written in pure C, no need of Python.
Windows command line program for Spleeter, written in pure C, no need of Python.

SpleeterMsvcExe is a Windows command line program for Spleeter, which can be used directly. It is written in pure C language, using ffmpeg to read and write audio files, and using Tensorflow C API to make use of Spleeter models. No need to install Python environment, and it does not contain anything related to Python.

Sep 23, 2022
为了让 Windows 平台上的 ssh agent 能适配多种 ssh client 和在 wsl 环境下使用的工具

ssh-agent-bridge 为了让 Windows 平台上的 ssh agent 能适配多种 ssh client 和在 wsl 环境下使用的工具 Windows 平台上存在着多种 ssh agent 的实现,由于 Windows 平台的特殊性,这些 agent 程序都有一套自行实现的进程间通

Jun 13, 2022
A Command-Line-Interface Debugger for 64-bit Windows written in C.

Debugger-For-Windows A command-line-interface debugger for 64-bit Windows. [email protected]:/mnt/c/Projects/C/Debugger$ ./Debugger.exe ./Tests/test.ex

Nov 3, 2021
Windows Package Manager CLI (aka winget)
Windows Package Manager CLI (aka winget)

Welcome to the Windows Package Manager Client (aka winget.exe) repository This repository contains the source code for the Windows Package Manager Cli

Oct 1, 2022
udmp-parser: A Windows user minidump C++ parser library.
udmp-parser: A Windows user minidump C++ parser library.

udmp-parser: A Windows user minidump C++ parser library. This is a cross-platform (Windows / Linux / OSX / x86 / x64) C++ library that parses Windows

Sep 22, 2022
A simple header-only C++ argument parser library. Supposed to be flexible and powerful, and attempts to be compatible with the functionality of the Python standard argparse library (though not necessarily the API).

args Note that this library is essentially in maintenance mode. I haven't had the time to work on it or give it the love that it deserves. I'm not add

Sep 22, 2022
CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface.
CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface.

CLI11: Command line parser for C++11 What's new • Documentation • API Reference CLI11 is a command line parser for C++11 and beyond that provides a ri

Sep 26, 2022