• Stars
    star
    172
  • Rank 213,273 (Top 5 %)
  • Language
    C++
  • License
    BSD 2-Clause "Sim...
  • Created about 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A single file multi-platform (Unix, Windows) C++ header-only linenoise-based readline library.

cpp-linenoise

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

This library gathered code from following excellent libraries, clean it up, and put it into a C++ header file for convenience.

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

Usage

#include "linenoise.hpp"

...

const auto path = "history.txt";

// Setup completion words every time when a user types
linenoise::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
linenoise::SetMultiLine(true);

// Set max length of the history
linenoise::SetHistoryMaxLen(4);

// Load history
linenoise::LoadHistory(path);

while (true) {
    // Read line
    std::string line;
    auto quit = linenoise::Readline("hello> ", line);

    if (quit) {
        break;
    }

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

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

// Save history
linenoise::SaveHistory(path);

API

namespace linenoise;

std::string Readline(const char* prompt);

void SetMultiLine(bool multiLineMode);

typedef std::function<void (const char* editBuffer, std::vector<std::string>& completions)> CompletionCallback;

void SetCompletionCallback(CompletionCallback fn);

bool SetHistoryMaxLen(size_t len);

bool LoadHistory(const char* path);

bool SaveHistory(const char* path);

bool AddHistory(const char* line);

const std::vector<std::string>& GetHistory();

Tested compilers

  • Visual Studio 2015
  • Clang 3.5
  • GCC 6.3.1

License

BSD license (© 2015 Yuji Hirose)

More Repositories

1

cpp-httplib

A C++ header-only HTTP/HTTPS server and client library
C++
11,247
star
2

cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
C++
789
star
3

react-typescript-electron-sample-with-create-react-app-and-electron-builder

React-TypeScript-Electron sample with Create React App and Electron Builder
TypeScript
429
star
4

maxminddb

Pure Ruby GeoIP2 MaxMind DB reader.
Ruby
289
star
5

cpp-unicodelib

A C++17 header-only Unicode library. (Unicode 15.1)
C++
80
star
6

go-peg

Yet another PEG (Parsing Expression Grammars) parser generator for Go
Go
60
star
7

cpp-mmaplib

A single file C++11 header-only memory mapped file library.
C++
53
star
8

cpp-sqlitelib

C++ SQLite wrapper library
C
48
star
9

cpp-fstlib

A single file C++17 header-only Minimal Acyclic Subsequential Transducers, or Finite State Transducers
C++
46
star
10

vscode-filtertext

Filter Text extension for VS Code
TypeScript
28
star
11

cpp-searchlib

A C++17 full-text search engine library
C++
27
star
12

pl0-jit-compiler

A tiny PL/0 JIT compiler in less than 900 LOC with LLVM and PEG parser.
C++
26
star
13

monkey-cpp

An interpreter for the Monkey programming language written in C++
C++
23
star
14

cpp-zipper

A single file C++ header-only minizip wrapper library
C++
20
star
15

cpp-threadpool

C++11 header-only thread pool library
C++
17
star
16

fizzbuzzlang

A Programming Language just for writing Fizz Buzz program. :)
C++
6
star
17

culebra

Culebra Programming Language
C++
5
star
18

cpp-jsonlib

A C++17 single-file header-only library to wrap RapidJSON SAX interface
C++
5
star
19

math-challenge

Mental math training app
Svelte
3
star
20

yet-another-electron-react-typescript-boilerplate

Yet another Electron-React-TypeScript boilerplate with Create React App and Electron Builder. No eject is required.
TypeScript
3
star
21

mtlcpp

Utilities for Metal-cpp
C++
2
star
22

msl-dot-product-example

MSL Dot Product example
C++
2
star
23

yomi

Chinese Pinyin and Japanese Ruby generator using Kytea
C++
1
star
24

BibleReadingMenulet

Menulet for tracking daily Bible reading
Objective-C
1
star
25

immersion

Distraction free pager on Terminal
C++
1
star
26

gapi-ez

JavaScript library for easy accessing to the Google APIs Client Library for JavaScript
JavaScript
1
star
27

Undertone

Bible reading progress tracker
JavaScript
1
star
28

dds

PEGとC++11で作る言語処理系
C++
1
star
29

cpp-liblinear

A single file C++ header-only wrapper for LIBLINEAR library
C++
1
star