LineReader
is a C++ library that provides line-editing, and history capabilities for interactive command line programs.
Include the linereader.hpp
file, and compile the linereader.cpp
file together with your project.
To use LineReader
in you project,
#include "linereader.hpp"
#include <iostream>
int main(int argc, char **argv) {
auto lr = LineReader(".history_file");
const char *prompt = "> ";
while (lr) {
auto cmd = lr.readline(prompt);
if (!cmd.empty()) {
// parse and execute the command string.
// ...
}
}
std::cout << '\n' << "Bye!" << std::endl;
return 0;
}
C-f
is forCtrl + f
M-f
is forAlt + f
Key | Action |
---|---|
C-f or Right Arrow | move forward one character |
C-b or Left Arrow | move backward one character |
M-f | move forward one word |
M-b | move backward one word |
C-d or Delete | delete one character |
M-d | delete one word |
C-p or Up Arrow | edit previous line in history |
C-n or Down Arrow | edit next line in history |
M-l | lowercase word |
M-u | uppercase word |
M-c | capitalize word |
C-t | swap current character with previous character |
M-t | swap words |
C-u | kill (cut) text from cursor position to the beginning of the line |
C-k | kill (cut) text from cursor position to the end of the line |
C-y | yank (paste) text from kill ring |
M-y | (after C-y) cycle through kill ring |
- Terminal escape sequences have been tested on
xterm
only.