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.
- Host: GitHub
- URL: https://github.com/px86/linereader
- Owner: px86
- License: mit
- Created: 2022-02-09T16:33:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-13T16:36:04.000Z (about 3 years ago)
- Last Synced: 2025-01-26T03:42:10.983Z (5 months ago)
- Topics: line-editing, line-editor, readline
- Language: C++
- Homepage:
- Size: 45.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.org
- License: LICENSE
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"
#includeint 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.