Etermal
Embeddable Terminal and shell for OpenGL
|
Built in implementation of EShell. More...
#include <BasicShell.h>
Classes | |
struct | flag |
Contains various shell flags. More... | |
Public Types | |
typedef const std::vector< std::string > & | param_t |
Parameter type given to command callbacks. | |
typedef std::function< void(param_t args)> | callback_t |
Command callback. More... | |
typedef std::string | key_type |
The command string type. | |
typedef std::vector< callback_t > | commands_t |
Type used for the command container. | |
typedef std::function< void(const shellError &)> | errCallback_t |
Error callback. More... | |
typedef std::function< std::string(const std::string &)> | noCommandCallback_t |
No-command callback. More... | |
Public Member Functions | |
BasicShell () | |
Construct a shell. | |
BasicShell (const errCallback_t &callback) | |
Construct a shell with an error callback. More... | |
void | setErrorCallback (const errCallback_t &callback) |
Set the callback that will be called whenever a shellError is set. More... | |
void | setNoCommandCallback (const noCommandCallback_t &callback) |
Callback called when a given command could not be found. More... | |
errCallback_t | getErrorCallback () |
Gets the current error callback. More... | |
noCommandCallback_t | getNoCommandCallback () |
Gets the current no-command callback. More... | |
void | setPrompt (const std::string &str) |
Set the text that's displayed in the terminal when the shell is taking user input. More... | |
std::string | getPrompt () |
Gets the current prompt. More... | |
void | setFlags (flag::type flags) |
Set terminal flags. More... | |
void | setTerminal (ETerminal &terminal) |
Set the program frontend. More... | |
void | input (const std::string &commandString) override |
Send a command string to the shell to be processed. More... | |
void | cursorUp () override |
Called when the user attempts to move the cursor up when it's already at max height; think command history... | |
void | cursorDown () override |
Called when the user attempts to move the cursor down when it's already at max height; think command history... | |
void | add (const std::string &name, const callback_t &callback) |
Add a new command to the BasicShell. More... | |
void | alias (const std::string &name) |
Associate another name with the last added command. More... | |
void | postError (const std::string &location, const std::string &message, bool severe) |
Send an error to the error callback. More... | |
Built in implementation of EShell.
Basically just a copy of Shell that has a bunch of stuff ripped out of it.
typedef std::function<void(param_t args)> etm::BasicShell::callback_t |
Command callback.
Called when a command is invoked.
typedef std::function<void(const shellError&)> etm::BasicShell::errCallback_t |
Error callback.
Called when an error is detected.
typedef std::function<std::string(const std::string&)> etm::BasicShell::noCommandCallback_t |
No-command callback.
Return value should the be text to display to the user. The parameter is the command that was given.
etm::BasicShell::BasicShell | ( | const errCallback_t & | callback | ) |
Construct a shell with an error callback.
No errors are set in the constructor ATM, but it may still be a good idea to assure that errors get processed correctly.
[in] | callback | A callable callback |
void etm::BasicShell::add | ( | const std::string & | name, |
const callback_t & | callback | ||
) |
Add a new command to the BasicShell.
callback
is not callable, an error is set and the command is not added. [in] | name | The initial alias for the command |
[in] | callback | A callable callback for the command |
void etm::BasicShell::alias | ( | const std::string & | name | ) |
Associate another name with the last added command.
name
already exists as an alias to some other command, that alias gets re-pointed to the last command. In other words, this function overwrites any previous alias of the same name. [in] | name | The alias |
errCallback_t etm::BasicShell::getErrorCallback | ( | ) |
Gets the current error callback.
It will be callable.
noCommandCallback_t etm::BasicShell::getNoCommandCallback | ( | ) |
Gets the current no-command callback.
It will be callable.
std::string etm::BasicShell::getPrompt | ( | ) |
Gets the current prompt.
|
overridevirtual |
Send a command string to the shell to be processed.
Typically from user input.
[in] | commandString | The command string |
Implements etm::EShell.
void etm::BasicShell::postError | ( | const std::string & | location, |
const std::string & | message, | ||
bool | severe | ||
) |
Send an error to the error callback.
The given parameters are packaged into a shellError object.
[in] | location | The location at which the error was detected |
[in] | message | The error message |
[in] | severe | Whether the error is severe or not |
void etm::BasicShell::setErrorCallback | ( | const errCallback_t & | callback | ) |
Set the callback that will be called whenever a shellError
is set.
[in] | callback | A callable callback |
void etm::BasicShell::setFlags | ( | flag::type | flags | ) |
void etm::BasicShell::setNoCommandCallback | ( | const noCommandCallback_t & | callback | ) |
Callback called when a given command could not be found.
[in] | callback | A callable callback |
void etm::BasicShell::setPrompt | ( | const std::string & | str | ) |
Set the text that's displayed in the terminal when the shell is taking user input.
[in] | str | UTF-8 encoded string to display |
void etm::BasicShell::setTerminal | ( | ETerminal & | terminal | ) |
Set the program frontend.
The shell will fail at areas [ex. input(const std::string &commandString)] where it needs to display text to the terminal.
[in] | terminal | The terminal frontend |