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

Built in implementation of EShell. More...

#include <BasicShell.h>

Inheritance diagram for etm::BasicShell:
etm::EShell

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_tcommands_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...
 

Detailed Description

Built in implementation of EShell.

Basically just a copy of Shell that has a bunch of stuff ripped out of it.

See also
Terminal

Member Typedef Documentation

◆ callback_t

typedef std::function<void(param_t args)> etm::BasicShell::callback_t

Command callback.

Called when a command is invoked.

◆ errCallback_t

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

Error callback.

Called when an error is detected.

◆ noCommandCallback_t

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.

Constructor & Destructor Documentation

◆ BasicShell()

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.

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

◆ add()

void etm::BasicShell::add ( const std::string &  name,
const callback_t callback 
)

Add a new command to the BasicShell.

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]callbackA callable callback for the command
See also
alias(const std::string &name)
input(const std::string &commandString)

◆ alias()

void etm::BasicShell::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::BasicShell::getErrorCallback ( )

Gets the current error callback.

It will be callable.

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

◆ getNoCommandCallback()

noCommandCallback_t etm::BasicShell::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::BasicShell::getPrompt ( )

Gets the current prompt.

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

◆ input()

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

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::BasicShell::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::BasicShell::setFlags ( flag::type  flags)

Set terminal flags.

Parameters
[in]flagsThe flags to set
See also
flag

◆ setNoCommandCallback()

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

Parameters
[in]terminalThe terminal frontend

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