An open API service indexing awesome lists of open source software.

https://github.com/px86/linereader

C++ library providing line-editing and history capabilities for interactive command line programs.
https://github.com/px86/linereader

line-editing line-editor readline

Last synced: 3 months ago
JSON representation

C++ library providing line-editing and history capabilities for interactive command line programs.

Awesome Lists containing this project

README

        

#+TITLE: LineReader - A C++ Library For Line Editing
#+AUTHOR: Pushkar Raj

* About

=LineReader= is a C++ library that provides line-editing, and history capabilities for interactive command line programs.

* Usage

Include the =linereader.hpp= file, and compile the =linereader.cpp= file together with your project.

To use =LineReader= in you project,

#+begin_src cpp
#include "linereader.hpp"
#include

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;
}
#+end_src

* Key Bindings

- =C-f= is for =Ctrl + f=
- =M-f= is for =Alt + 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 |

* Notes

- Terminal escape sequences have been tested on =xterm= only.