{"id":13667426,"url":"https://github.com/yhirose/cpp-linenoise","last_synced_at":"2025-04-09T22:10:11.723Z","repository":{"id":30805927,"uuid":"34363047","full_name":"yhirose/cpp-linenoise","owner":"yhirose","description":"A single file multi-platform (Unix, Windows) C++ header-only linenoise-based readline library.","archived":false,"fork":false,"pushed_at":"2025-03-11T19:27:21.000Z","size":84,"stargazers_count":181,"open_issues_count":5,"forks_count":58,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T22:10:03.356Z","etag":null,"topics":["c-plus-plus","cpp","cpp11","header-only","linenoise","readline-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yhirose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-22T02:07:23.000Z","updated_at":"2025-03-11T19:27:26.000Z","dependencies_parsed_at":"2022-08-29T06:01:29.671Z","dependency_job_id":null,"html_url":"https://github.com/yhirose/cpp-linenoise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fcpp-linenoise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fcpp-linenoise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fcpp-linenoise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fcpp-linenoise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yhirose","download_url":"https://codeload.github.com/yhirose/cpp-linenoise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","cpp","cpp11","header-only","linenoise","readline-library"],"created_at":"2024-08-02T07:00:36.742Z","updated_at":"2025-04-09T22:10:11.704Z","avatar_url":"https://github.com/yhirose.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"cpp-linenoise\n=============\n\nMulti-platform (Unix, Windows) C++ header-only linenoise-based readline library.\n\nThis library gathered code from following excellent libraries, clean it up, and put it into a C++ header file for convenience.\n\n * `linenoise.h` and `linenoise.c` ([antirez/linenoise](https://github.com/antirez/linenoise))\n * `ANSI.c` ([adoxa/ansicon](https://github.com/adoxa/ansicon))\n * `Win32_ANSI.h` and `Win32_ANSI.c` ([MSOpenTech/redis](https://github.com/MSOpenTech/redis))\n\nThe licenses for the libraries are included in `linenoise.hpp`.\n\nUsage\n-----\n\n```c++\n#include \"linenoise.hpp\"\n\n...\n\nconst auto path = \"history.txt\";\n\n// Setup completion words every time when a user types\nlinenoise::SetCompletionCallback([](const char* editBuffer, std::vector\u003cstd::string\u003e\u0026 completions) {\n    if (editBuffer[0] == 'h') {\n        completions.push_back(\"hello\");\n        completions.push_back(\"hello there\");\n    }\n});\n\n// Enable the multi-line mode\nlinenoise::SetMultiLine(true);\n\n// Set max length of the history\nlinenoise::SetHistoryMaxLen(4);\n\n// Load history\nlinenoise::LoadHistory(path);\n\nwhile (true) {\n    // Read line\n    std::string line;\n    auto quit = linenoise::Readline(\"hello\u003e \", line);\n\n    if (quit) {\n        break;\n    }\n\n    cout \u003c\u003c  \"echo: '\" \u003c\u003c line \u003c\u003c \"'\" \u003c\u003c endl;\n\n    // Add text to history\n    linenoise::AddHistory(line.c_str());\n}\n\n// Save history\nlinenoise::SaveHistory(path);\n```\n\nAPI\n---\n\n```c++\nnamespace linenoise;\n\nstd::string Readline(const char* prompt);\n\nvoid SetMultiLine(bool multiLineMode);\n\ntypedef std::function\u003cvoid (const char* editBuffer, std::vector\u003cstd::string\u003e\u0026 completions)\u003e CompletionCallback;\n\nvoid SetCompletionCallback(CompletionCallback fn);\n\nbool SetHistoryMaxLen(size_t len);\n\nbool LoadHistory(const char* path);\n\nbool SaveHistory(const char* path);\n\nbool AddHistory(const char* line);\n\nconst std::vector\u003cstd::string\u003e\u0026 GetHistory();\n```\n\nTested compilers\n----------------\n\n  * Visual Studio 2015\n  * Clang 3.5\n  * GCC 6.3.1\n\nLicense\n-------\n\nBSD license (© 2015 Yuji Hirose)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirose%2Fcpp-linenoise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyhirose%2Fcpp-linenoise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirose%2Fcpp-linenoise/lists"}