Skip to content

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

License

Notifications You must be signed in to change notification settings

px86/linereader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LineReader - A C++ Library For Line Editing

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,

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

Key Bindings

  • C-f is for Ctrl + f
  • M-f is for Alt + f
KeyAction
C-f or Right Arrowmove forward one character
C-b or Left Arrowmove backward one character
M-fmove forward one word
M-bmove backward one word
C-d or Deletedelete one character
M-ddelete one word
C-p or Up Arrowedit previous line in history
C-n or Down Arrowedit next line in history
M-llowercase word
M-uuppercase word
M-ccapitalize word
C-tswap current character with previous character
M-tswap words
C-ukill (cut) text from cursor position to the beginning of the line
C-kkill (cut) text from cursor position to the end of the line
C-yyank (paste) text from kill ring
M-y(after C-y) cycle through kill ring

Notes

  • Terminal escape sequences have been tested on xterm only.

About

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

Topics

Resources

License

Stars

Watchers

Forks