• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    C++
  • License
    BSD 2-Clause "Sim...
  • Created over 9 years ago
  • Updated over 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++
12,955
star
2

cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
C++
893
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
447
star
4

maxminddb

Pure Ruby GeoIP2 MaxMind DB reader.
Ruby
298
star
5

cpp-unicodelib

A C++17 header-only Unicode library. (Unicode 16.0.0)
C++
96
star
6

go-peg

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

cpp-mmaplib

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

cpp-fstlib

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

cpp-sqlitelib

C++ SQLite wrapper library
C
51
star
10

cpp-searchlib

A C++17 full-text search engine library
C++
31
star
11

vscode-filtertext

Filter Text extension for VS Code
TypeScript
30
star
12

pl0-jit-compiler

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

monkey-cpp

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

cpp-zipper

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

cpp-threadpool

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

fizzbuzzlang

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

mtlcpp

Utilities for Metal-cpp
C++
6
star
18

cpp-jsonlib

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

culebra

Culebra Programming Language
C++
5
star
20

math-challenge

Mental math training app
Svelte
3
star
21

msl-dot-product-example

MSL Dot Product example
C++
2
star
22

yomi

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

BibleReadingMenulet

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

gapi-ez

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

Undertone

Bible reading progress tracker
JavaScript
1
star
26

dds

PEGใจC++11ใงไฝœใ‚‹่จ€่ชžๅ‡ฆ็†็ณป
C++
1
star
27

cpp-liblinear

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

immersion

Distraction free pager on Terminal
C++
1
star