Handles command line input with history. More...
#include <Command_input.hpp>
Public Member Functions | |
Command_input (int n_history=unlimited) | |
Constructs a Command_input and sets the history buffer size. | |
std::string | get () |
Obtains a line of input from the command line. | |
Static Public Attributes | |
static const int | unlimited = -1 |
opaque value used to communicate no limit on the size of the history buffer | |
Handles command line input with history.
hexed::Command_input::Command_input | ( | int | n_history = unlimited | ) |
Constructs a Command_input
and sets the history buffer size.
All calls to get()
with this Command_input
instance will share the same history. If n_history
is not Command_input::unlimited
, whenever the history reaches a size of n_history + 1
entries, the earliest entry will be forgotten to keep a size of n_history
.
std::string hexed::Command_input::get | ( | ) |
Obtains a line of input from the command line.
Waits for input until a newline or EOF is received. This input is then returned as a string and added to the history buffer. The terminal newline or EOF is not included, and only printable characters are included. The up and down arrows can be used to access and navigate the history buffer. Empty lines are not added to the history, nor are any lines that are identical to the previous line.