Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.51 KB

README.md

File metadata and controls

71 lines (49 loc) · 1.51 KB

cpp-linenoise

Multi-platform (Unix, Windows) C++ header-only linenoise-based readline library.

This version of cpp-linenoise is derived from https://github.com/yhirose/cpp-linenoise, which is in turn assembled from the following libraries:

The licenses for the libraries are included in linenoise.hpp.

Usage

#include "linenoise.hpp"

...

const auto path = "history.txt";

linenoise::linenoiseState l("hello> ");

// Setup completion words every time when a user types
l.SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) {
    if (editBuffer[0] == 'h') {
        completions.push_back("hello");
        completions.push_back("hello there");
    }
});

// Enable the multi-line mode
l.EnableMultiLine();

// Set max length of the history
l.SetHistoryMaxLen(4);

// Load history
l.LoadHistory(path);

while (true) {
    // Read line
    std::string line;
    auto quit = l.Readline(line);

    if (quit) {
        break;
    }

    cout <<  "echo: '" << line << "'" << endl;

    // Add text to history
    l.AddHistory(line.c_str());
}

// Save history
l.SaveHistory(path);

API

The public methods on the linenoiseState class are considered the public API.

License

BSD license (© 2015 Yuji Hirose)