Linux terminal input and cursor handling utility(for CLI applications)
This repository provides the readLine functionality for handling newline terminated user inputs. It is based on termios functions. The termios functions describe a general terminal interface that is provided to control asynchronous communications ports in Linux.
- Provides line based input functionality.
- Handles cursor movement.
- User can edit the input using deletion and insertion operations.
- The utility tracks user input history.
- User can navigate through the previously typed input using up and down arrow keys.
Input is stored using a LRBuffer data structure(rather than a simple 1D dyanamic array).
Time-comlexity of continuous character insertion and deletion operation(without manual cursor changes in between) is of the order O(1).
Time-complexity of an insertion or deletion right after changing the cursor position is of the order O(n).
Makefile is used for library installation. Default prefix is /usr/local/lib/ (it will be a system-wide installation)
To install readLine run the following commands:
$make
$sudo make install
Note: You can do a user-only installation as well. For that you will need to edit the Makefile and add prefix of your own choice. In that case steps will be:
$make
$make install
test.c:
#include <readLine/readline.h>
int main() {
char* user-input = readLine();
return 0;
}
Compile it and run:
$gcc -o test test.c -lreadLine
$./test
- Auto-completion of user input based of input history.