Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yhirose/cpp-linenoise
A single file multi-platform (Unix, Windows) C++ header-only linenoise-based readline library.
https://github.com/yhirose/cpp-linenoise
c-plus-plus cpp cpp11 header-only linenoise readline-library
Last synced: 7 days ago
JSON representation
A single file multi-platform (Unix, Windows) C++ header-only linenoise-based readline library.
- Host: GitHub
- URL: https://github.com/yhirose/cpp-linenoise
- Owner: yhirose
- License: bsd-2-clause
- Created: 2015-04-22T02:07:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T08:29:14.000Z (over 2 years ago)
- Last Synced: 2024-10-22T20:24:08.369Z (16 days ago)
- Topics: c-plus-plus, cpp, cpp11, header-only, linenoise, readline-library
- Language: C++
- Homepage:
- Size: 78.1 KB
- Stars: 173
- Watchers: 9
- Forks: 53
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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.
* `linenoise.h` and `linenoise.c` ([antirez/linenoise](https://github.com/antirez/linenoise))
* `ANSI.c` ([adoxa/ansicon](https://github.com/adoxa/ansicon))
* `Win32_ANSI.h` and `Win32_ANSI.c` ([MSOpenTech/redis](https://github.com/MSOpenTech/redis))The licenses for the libraries are included in `linenoise.hpp`.
Usage
-----```c++
#include "linenoise.hpp"...
const auto path = "history.txt";
// Setup completion words every time when a user types
linenoise::SetCompletionCallback([](const char* editBuffer, std::vector& 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
---```c++
namespace linenoise;std::string Readline(const char* prompt);
void SetMultiLine(bool multiLineMode);
typedef std::function& 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& GetHistory();
```Tested compilers
----------------* Visual Studio 2015
* Clang 3.5
* GCC 6.3.1License
-------BSD license (© 2015 Yuji Hirose)