Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e20e7f1
Reduce variable scope
starseeker Mar 7, 2025
48b55c5
Make most linenoise functions into methods on a class.
starseeker Mar 7, 2025
27e4fd8
Support previous API style
starseeker Mar 10, 2025
9bf9fb5
Add a mutex to protect RefreshLine if multiple threads need to call it.
starseeker Mar 10, 2025
1aface1
Adjust how history and its up/down arrow browsing are handled.
starseeker Mar 10, 2025
80fe6b2
We don't want to hang if we can't read anything from stdin
starseeker Mar 10, 2025
854ec25
Add WipeLine and ClearScreen methods.
starseeker Mar 10, 2025
cab53d8
See if we can avoid using strcasecmp
starseeker Mar 10, 2025
debd295
Correct behavior for sending commands
starseeker Mar 10, 2025
d3b0c33
Misc. fixes and adjustments
starseeker Mar 10, 2025
eb222da
Compare against the correct string
starseeker Mar 10, 2025
1793d0e
Use inline
starseeker Mar 11, 2025
9ed3176
Restore inlines to allow multiple includes
starseeker Mar 11, 2025
658c26f
Add an l_ prefix to all class member variables.
starseeker Mar 11, 2025
e17e955
Stray static global mess with history rename. Add some comments.
starseeker Mar 11, 2025
b5d3c58
Eliminate a couple more globals
starseeker Mar 11, 2025
a66dda2
Back out history changes
starseeker Mar 11, 2025
507d831
Use suffix character for class variables
starseeker Mar 11, 2025
b68295f
Remove unnecessary prefixes from internal class method names
starseeker Mar 11, 2025
58ae27f
Clean up class API slightly.
starseeker Mar 11, 2025
060e10c
Unused define
starseeker Mar 11, 2025
421ef3e
Move multiinclude test files to subdir
starseeker Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ include_directories(.)
add_definitions("-std=c++1y")

add_executable(example example.cpp)
add_executable(example_old example_old.cpp)

add_executable(multiinclude
multiinclude/main.cpp
multiinclude/f1.cpp
multiinclude/f2.cpp
)

26 changes: 15 additions & 11 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ int main(int argc, const char** argv)
{
const auto path = "history.txt";

#ifdef _WIN32
const char *prompt = "hello> ";
#else
const char *prompt = "\033[32mこんにちは\x1b[0m> ";
#endif

linenoise::linenoiseState l(prompt);

// Enable the multi-line mode
linenoise::SetMultiLine(true);
l.EnableMultiLine();

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

// Setup completion words every time when a user types
linenoise::SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) {
l.SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) {
if (editBuffer[0] == 'h') {
#ifdef _WIN32
completions.push_back("hello こんにちは");
Expand All @@ -27,15 +35,11 @@ int main(int argc, const char** argv)
});

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

while (true) {
std::string line;
#ifdef _WIN32
auto quit = linenoise::Readline("hello> ", line);
#else
auto quit = linenoise::Readline("\033[32mこんにちは\x1b[0m> ", line);
#endif
auto quit = l.Readline(line);

if (quit) {
break;
Expand All @@ -44,10 +48,10 @@ int main(int argc, const char** argv)
cout << "echo: '" << line << "'" << endl;

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

// Save history
linenoise::SaveHistory(path);
l.SaveHistory(path);
}

return 0;
Expand Down
54 changes: 54 additions & 0 deletions example/example_old.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
#include "../linenoise.hpp"

using namespace std;

int main(int argc, const char** argv)
{
const auto path = "history.txt";

// Enable the multi-line mode
linenoise::SetMultiLine(true);

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

// Setup completion words every time when a user types
linenoise::SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) {
if (editBuffer[0] == 'h') {
#ifdef _WIN32
completions.push_back("hello こんにちは");
completions.push_back("hello こんにちは there");
#else
completions.push_back("hello");
completions.push_back("hello there");
#endif
}
});

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

while (true) {
std::string line;
#ifdef _WIN32
auto quit = linenoise::Readline("hello> ", line);
#else
auto quit = linenoise::Readline("\033[32mこんにちは\x1b[0m> ", line);
#endif

if (quit) {
break;
}

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

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

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

return 0;
}
8 changes: 8 additions & 0 deletions example/multiinclude/f1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "../linenoise.hpp"

void f1()
{
linenoise::linenoiseState l("p1");
l.EnableMultiLine();
}

8 changes: 8 additions & 0 deletions example/multiinclude/f2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "../linenoise.hpp"

void f2()
{
linenoise::linenoiseState l("p2");
l.EnableMultiLine();
}

9 changes: 9 additions & 0 deletions example/multiinclude/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extern void f1();
extern void f2();

int main(int argc, const char** argv)
{
f1();
f2();
return 0;
}
Loading