Etermal
Embeddable Terminal and shell for OpenGL
Classes | Public Types | Public Member Functions | List of all members
etm::Shell Class Reference

Built in implementation of EShell. More...

#include <Shell.h>

Inheritance diagram for etm::Shell:
etm::EShell

Classes

struct  Command
 Container for a command callback and its argument processor. More...
 
struct  flag
 Contains various shell flags. More...
 

Public Types

typedef std::function< void(Shell &, ETerminal &, Args &)> callback_t
 Command callback. More...
 
typedef std::string key_type
 The command string type.
 
typedef unsigned int comid_t
 Type used for command IDs.
 
typedef std::map< comid_t, Commandcommands_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

 Shell ()
 Construct a shell.
 
 Shell (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...
 
comid_t addCommand (const std::string &name, const ArgFilter &filter, const callback_t &callback)
 Add a new command to the Shell. More...
 
void alias (comid_t id, const std::string &name)
 Associate another name with the given command. 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...
 

Detailed Description

Built in implementation of EShell.

See also
Terminal

Member Typedef Documentation

◆ callback_t

typedef std::function<void(Shell&,ETerminal&,Args&)> etm::Shell::callback_t

Command callback.

Called when a command is invoked.

◆ errCallback_t

typedef std::function<void(const shellError&)> etm::Shell::errCallback_t

Error callback.

Called when an error is detected.

◆ noCommandCallback_t

typedef std::function<std::string(const std::string&)> etm::Shell::noCommandCallback_t

No-command callback.

Return value should the be text to display to the user. The parameter is the command that was given.

Constructor & Destructor Documentation

◆ Shell()

etm::Shell::Shell ( 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.

Note
The error callback isn't set if it's not callable
Parameters
[in]callbackA callable callback
See also
setErrorCallback(const errCallback_t &callback)

Member Function Documentation

◆ addCommand()

comid_t etm::Shell::addCommand ( const std::string &  name,
const ArgFilter filter,
const callback_t callback 
)

Add a new command to the Shell.

Note
If the parameter callback is not callable, an error is set and the command is not added.
Parameters
[in]nameThe initial alias for the command
[in]filterThe command filter for the command
[in]callbackA callable callback for the command
See also
alias(const std::string &name)
input(const std::string &commandString)
Returns
ID of the command (used to modify it), or zero if an error occurred.

◆ alias() [1/2]

void etm::Shell::alias ( comid_t  id,
const std::string &  name 
)

Associate another name with the given command.

Note
An error is set if id is invalid (doesn't exist)
If 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.
Parameters
[in]idThe ID of the command
[in]nameThe alias

◆ alias() [2/2]

void etm::Shell::alias ( const std::string &  name)

Associate another name with the last added command.

Note
An error is set if there aren't any commands
If 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.
Parameters
[in]nameThe alias

◆ getErrorCallback()

errCallback_t etm::Shell::getErrorCallback ( )

Gets the current error callback.

It will be callable.

Returns
The callback
See also
setErrorCallback(const errCallback_t &callback)

◆ getNoCommandCallback()

noCommandCallback_t etm::Shell::getNoCommandCallback ( )

Gets the current no-command callback.

It will be callable.

Returns
The callback
See also
setNoCommandCallback(const noCommandCallback_t &callback)

◆ getPrompt()

std::string etm::Shell::getPrompt ( )

Gets the current prompt.

Returns
The promt as a UTF-8 encoded string
See also
setPrompt(const std::string &str)

◆ input()

void etm::Shell::input ( const std::string &  commandString)
overridevirtual

Send a command string to the shell to be processed.

Typically from user input.

Parameters
[in]commandStringThe command string

Implements etm::EShell.

◆ postError()

void etm::Shell::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.

Parameters
[in]locationThe location at which the error was detected
[in]messageThe error message
[in]severeWhether the error is severe or not

◆ setErrorCallback()

void etm::Shell::setErrorCallback ( const errCallback_t callback)

Set the callback that will be called whenever a shellError is set.

Note
The callback isn't set if it's not callable
Parameters
[in]callbackA callable callback
See also
errCallback_t
getErrorCallback()

◆ setFlags()

void etm::Shell::setFlags ( flag::type  flags)

Set terminal flags.

Parameters
[in]flagsThe flags to set
See also
flag

◆ setNoCommandCallback()

void etm::Shell::setNoCommandCallback ( const noCommandCallback_t callback)

Callback called when a given command could not be found.

Note
The callback isn't set if it's not callable
Parameters
[in]callbackA callable callback
See also
noCommandCallback_t
getNoCommandCallback()

◆ setPrompt()

void etm::Shell::setPrompt ( const std::string &  str)

Set the text that's displayed in the terminal when the shell is taking user input.

Parameters
[in]strUTF-8 encoded string to display
See also
getPrompt()
input(const std::string &commandString)
setTerminal(ETerminal &terminal)

◆ setTerminal()

void etm::Shell::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.

Parameters
[in]terminalThe terminal frontend

The documentation for this class was generated from the following file: