Orxonox  0.0.5 Codename: Arcturus
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
orxonox::Shell Class Reference

The Shell is the logical component of the console that displays output to the user and allows him to enter commands. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/command/Shell.h>

Inheritance diagram for orxonox::Shell:
orxonox::BaseWriter orxonox::DevModeListener orxonox::SubcontextOutputListener orxonox::Listable orxonox::OutputListener orxonox::Identifiable

Public Types

typedef std::list< std::pair< std::string, LineType > > LineList
 
enum  LineType {
  LineType::DebugOutput = debug_output, LineType::Message = message, LineType::UserError = user_error, LineType::UserWarning = user_warning,
  LineType::UserStatus = user_status, LineType::UserInfo = user_info, LineType::InternalError = internal_error, LineType::InternalWarning = internal_warning,
  LineType::InternalStatus = internal_status, LineType::InternalInfo = internal_info, LineType::Verbose = verbose, LineType::VerboseMore = verbose_more,
  LineType::VerboseUltra = verbose_ultra, LineType::Cout, LineType::Input, LineType::Command,
  LineType::Result, LineType::Hint
}
 Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use. More...
 

Public Member Functions

 Shell (const std::string &consoleName="", bool bScrollable=true)
 Constructor: Initializes the values. More...
 
 ~Shell ()
 Destructor. More...
 
void addLine (const std::string &line, LineType type=LineType::DebugOutput)
 Adds a line to the internal output buffer. More...
 
void addOutput (const std::string &text, LineType type=LineType::DebugOutput)
 Adds multiple lines to the internal output buffer. More...
 
void clearOutput ()
 Clears the list of output-lines. More...
 
void commandHistoryLengthChanged ()
 Config-value callback: Called when the length of the command history has changed in the config-file. More...
 
void commandHistoryOffsetChanged ()
 Config-value callback: Called when the history offset has changed in the config-file. More...
 
unsigned int getCursorPosition () const
 Returns the current position of the cursor in the input buffer. More...
 
LineList::const_iterator getEndIterator () const
 Returns the end() iterator of the list of output-lines. More...
 
const std::string & getInput () const
 Returns the current content of the input buffer (the text which was entered by the user) More...
 
InputBuffergetInputBuffer ()
 Returns the input buffer which is needed by the user to enter text into the shell. More...
 
LineList::const_iterator getNewestLineIterator () const
 Returns an iterator to the newest line of output (except if the user is currently scrolling through the output). More...
 
unsigned int getNumLines () const
 Returns the number of output-lines that are displayed in the shell. More...
 
unsigned int getScrollPosition () const
 Returns the line which is currently viewed if the user scrolls through the older output-lines in the shell. More...
 
void registerListener (ShellListener *listener)
 Registers a shell listener which listens for changes in this shell. More...
 
void setConfigValues ()
 Defines the config values. More...
 
void setCursorPosition (unsigned int cursor)
 Changes the position of the cursor in the input buffer. More...
 
void unregisterListener (ShellListener *listener)
 Unregisters a shell listener. More...
 
- Public Member Functions inherited from orxonox::BaseWriter
 BaseWriter (const std::string &name, bool bRegister=true)
 Constructor: Initializes the config-values. More...
 
virtual ~BaseWriter ()
 Destructor. More...
 
void changedConfigurableAdditionalContexts ()
 Called if the config-vector of accepted contexts has changed, updates the masks in SubcontextOutputListener. More...
 
void changedConfigurableAdditionalContextsLevel ()
 Called if the config value has changed, updates the corresponding mask in OutputListener. More...
 
void changedConfigurableLevel ()
 Called if the config value has changed, updates the corresponding mask in OutputListener. More...
 
std::string getConfigurableAdditionalContextsMaxLevelName () const
 Returns the name of the config value which defines the maximum output level of additional context. More...
 
std::string getConfigurableAdditionalContextsName () const
 Returns the name of the config vector which defines the additional contexts (and sub-contexts) More...
 
std::string getConfigurableMaxLevelName () const
 Returns the name of the config value which defines the maximum output level (independent of contexts). More...
 
const std::string & getName () const
 Returns the name of this instance. More...
 
void setAdditionalContextsLevelMax (OutputLevel max)
 Overwritten implementation of the function inherited from OutputListener, sets also the corresponding config-value. More...
 
void setLevelMax (OutputLevel max)
 Overwritten implementation of the function inherited from OutputListener, sets also the corresponding config-value. More...
 
- Public Member Functions inherited from orxonox::SubcontextOutputListener
 SubcontextOutputListener (bool bRegister=true)
 Constructor, initializes the context masks. More...
 
virtual ~SubcontextOutputListener ()
 Destructor. More...
 
virtual bool acceptsOutput (OutputLevel level, const OutputContextContainer &context) const override
 Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks, as well as the set of accepted sub-contexts. More...
 
const std::set< OutputContextSubID > & getSubcontexts () const
 
virtual void setAdditionalContextsMask (OutputContextMask mask) override
 Overwritten implementation of the function defined by OutputListener. More...
 
void setAdditionalSubcontexts (const std::set< const OutputContextContainer * > &subcontexts)
 Defines the set of accepted sub-contexts. More...
 
- Public Member Functions inherited from orxonox::OutputListener
 OutputListener (bool bRegister=true)
 Constructor, initializes the values and registers the instance at OutputManager if requested. More...
 
virtual ~OutputListener ()
 Destructor, unregisters the instance from OutputManager. More...
 
OutputLevel getAdditionalContextsLevelMask () const
 Returns the additional contexts level mask. More...
 
OutputContextMask getAdditionalContextsMask () const
 Returns the additional contexts mask. More...
 
OutputLevel getLevelMask () const
 Returns the level mask. More...
 
void registerListener (AdditionalContextListener *listener)
 Adds a listener to the list. More...
 
void setAdditionalContextsLevelMask (OutputLevel mask)
 Defines the level mask of additional contexts. More...
 
void setAdditionalContextsLevelMax (OutputLevel max)
 Defines the level mask of additional contexts in a way which accepts all output up to the level max. More...
 
void setAdditionalContextsLevelRange (OutputLevel min, OutputLevel max)
 Defines the level mask of additional contexts in a way which accepts all output between the levels min and max. More...
 
void setLevelMask (OutputLevel mask)
 Defines the level mask. More...
 
void setLevelMax (OutputLevel max)
 Defines the level mask in a way which accepts all output up to the level max. More...
 
void setLevelRange (OutputLevel min, OutputLevel max)
 Defines the level mask in a way which accepts all output between the levels min and max. More...
 
virtual void unfilteredOutput (OutputLevel level, const OutputContextContainer &context, const std::vector< std::string > &lines)
 Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function. More...
 
void unregisterListener (AdditionalContextListener *listener)
 Removes a listener from the list. More...
 
- Public Member Functions inherited from orxonox::DevModeListener
 DevModeListener ()
 
virtual ~DevModeListener ()=default
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 

Static Public Member Functions

static unsigned int getCacheSize ()
 Returns the cache size that is actually used in CommandExecutor, but placed here for better readability of the config file. More...
 
- Static Public Member Functions inherited from orxonox::BaseWriter
static std::string getConfigurableSectionName ()
 Returns the (static) name of the section wherein the config-values are defined. More...
 

Private Member Functions

 Shell (const Shell &)=delete
 
void addToHistory (const std::string &command)
 Adds a command to the history of entered commands and writes it to the config-file. More...
 
void backspace ()
 InputBuffer callback: Called if a key was pressed that deletes the character before the cursor (usually [backspace]). More...
 
void clearInput ()
 Clears the text in the input buffer. More...
 
void configureInputBuffer ()
 Registers this object as listener for different key-events at the input buffer. More...
 
void cursorEnd ()
 InputBuffer callback: Called if a key was pressed that moves the input cursor the end of the input line (usually [end]). More...
 
void cursorHome ()
 InputBuffer callback: Called if a key was pressed that moves the input cursor the beginning of the input line (usually [home]). More...
 
void cursorLeft ()
 InputBuffer callback: Called if a key was pressed that moves the input cursor the left (usually [arrow left]). More...
 
void cursorRight ()
 InputBuffer callback: Called if a key was pressed that moves the input cursor the right (usually [arrow right]). More...
 
void deleteChar ()
 InputBuffer callback: Called if a key was pressed that deletes the character after the cursor (usually [delete]). More...
 
virtual void devModeChanged (bool value) override
 Called upon changes in the development mode (by Core) Behaviour details see Core::devModeChanged. More...
 
void execute ()
 InputBuffer callback: Called if a key was pressed that executes a command (usually [return]). More...
 
void exit ()
 InputBuffer callback: Called if a key was pressed that clears the text in the input buffer or closes the shell (usually [esc]). More...
 
const std::string & getFromHistory () const
 Returns a command from the history of entered commands (usually the most recent history entry, but the user can scroll through the history). More...
 
void hintAndComplete ()
 InputBuffer callback: Called if a key was pressed that shows hints and completes a command (usually [tab]). More...
 
void historyDown ()
 InputBuffer callback: Called if a key was pressed that scrolls downwards through the history of entered commands (usually [arrow down]). More...
 
void historySearchDown ()
 InputBuffer callback: Called if a key was pressed that searches downwards through the history for a command stat starts like the one the user is currently typing (usually [page down]). Only if the shell is not scrollable. More...
 
void historySearchUp ()
 InputBuffer callback: Called if a key was pressed that searches upwards through the history for a command stat starts like the one the user is currently typing (usually [page up]). Only if the shell is not scrollable. More...
 
void historyUp ()
 InputBuffer callback: Called if a key was pressed that scrolls upwards through the history of entered commands (usually [arrow up]). More...
 
void inputChanged ()
 InputBuffer callback: Called if the input changes. More...
 
Shelloperator= (const Shell &)=delete
 
virtual void printLine (const std::string &line, OutputLevel level) override
 Inherited from BaseWriter (LogListener), called if a new line of output was sent. More...
 
void scrollDown ()
 InputBuffer callback: Called if a key was pressed that scrolls downwards through the output history (usually [page down]). Only if the shell is scrollable. More...
 
void scrollUp ()
 InputBuffer callback: Called if a key was pressed that scrolls upwards through the output history (usually [page up]). Only if the shell is scrollable. More...
 
template<void(ShellListener::*)() F>
void updateListeners ()
 Iterates through all registered shell listeners and calls the function F. More...
 

Private Attributes

const bool bScrollable_
 If true, the user can scroll through the output-lines. More...
 
std::vector< std::string > commandHistory_
 The history of commands that were entered by the user. More...
 
unsigned int historyOffset_
 The command history is a circular buffer, this variable defines the current write-offset. More...
 
unsigned int historyPosition_
 If the user scrolls through the history of entered commands (stored in commandHistory_), this contains the currently viewed history entry. More...
 
InputBufferinputBuffer_
 The input buffer that is needed by the user to enter text. More...
 
std::list< ShellListener * > listeners_
 The registered shell listeners. More...
 
unsigned int maxHistoryLength_
 The maximum number of saved commands. More...
 
LineList outputLines_
 A list of all output-lines that were displayed in the shell so far. More...
 
LineList::const_iterator scrollIterator_
 An iterator to an entry of the list of output-lines, changes if the user scrolls through the output in the shell. More...
 
unsigned int scrollPosition_
 The number of the line that is currently being referenced by scrollIterator_. More...
 

Static Private Attributes

static unsigned int cacheSize_s
 The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is not configurable. More...
 

Additional Inherited Members

- Public Attributes inherited from orxonox::BaseWriter
std::vector< std::string > configurableAdditionalContexts_
 Config vector, used to define the additional contexts (and sub-contexts) More...
 
int configurableAdditionalContextsMaxLevel_
 Config value, used to define the maximum output level of additional context. More...
 
int configurableMaxLevel_
 Config value, used to define the maximum output level (independent of contexts) More...
 
- Protected Member Functions inherited from orxonox::BaseWriter
virtual void output (OutputLevel level, const OutputContextContainer &context, const std::vector< std::string > &lines) override
 This function is inherited from OutputListener, each message is split into lines and sent to printLine(). More...
 
- Protected Member Functions inherited from orxonox::OutputListener
const std::vector< AdditionalContextListener * > & getListeners () const
 

Detailed Description

The Shell is the logical component of the console that displays output to the user and allows him to enter commands.

The Shell gathers output sent from OutputManager by inheriting from BaseWriter. The output-lines are stored in the shell, so they can be displayed in a graphical console. Additionally the Shell has an InputBuffer which is needed by the user to enter commands.

Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole.

Member Typedef Documentation

typedef std::list<std::pair<std::string, LineType> > orxonox::Shell::LineList

Member Enumeration Documentation

Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use.

Enumerator
DebugOutput 
Message 
UserError 
UserWarning 
UserStatus 
UserInfo 
InternalError 
InternalWarning 
InternalStatus 
InternalInfo 
Verbose 
VerboseMore 
VerboseUltra 
Cout 
Input 
Command 
Result 
Hint 

Constructor & Destructor Documentation

orxonox::Shell::Shell ( const std::string &  consoleName = "",
bool  bScrollable = true 
)

Constructor: Initializes the values.

Parameters
consoleNameThe name of the shell - used to define the name of the soft-debug-level config-value
bScrollableIf true, the user is allowed to scroll through the output-lines
orxonox::Shell::~Shell ( )

Destructor.

orxonox::Shell::Shell ( const Shell )
privatedelete

Member Function Documentation

void orxonox::Shell::addLine ( const std::string &  line,
LineType  type = LineType::DebugOutput 
)

Adds a line to the internal output buffer.

void orxonox::Shell::addOutput ( const std::string &  text,
LineType  type = LineType::DebugOutput 
)

Adds multiple lines to the internal output buffer.

void orxonox::Shell::addToHistory ( const std::string &  command)
private

Adds a command to the history of entered commands and writes it to the config-file.

void orxonox::Shell::backspace ( )
private

InputBuffer callback: Called if a key was pressed that deletes the character before the cursor (usually [backspace]).

void orxonox::Shell::clearInput ( )
private

Clears the text in the input buffer.

void orxonox::Shell::clearOutput ( )

Clears the list of output-lines.

void orxonox::Shell::commandHistoryLengthChanged ( )

Config-value callback: Called when the length of the command history has changed in the config-file.

void orxonox::Shell::commandHistoryOffsetChanged ( )

Config-value callback: Called when the history offset has changed in the config-file.

void orxonox::Shell::configureInputBuffer ( )
private

Registers this object as listener for different key-events at the input buffer.

void orxonox::Shell::cursorEnd ( )
private

InputBuffer callback: Called if a key was pressed that moves the input cursor the end of the input line (usually [end]).

void orxonox::Shell::cursorHome ( )
private

InputBuffer callback: Called if a key was pressed that moves the input cursor the beginning of the input line (usually [home]).

void orxonox::Shell::cursorLeft ( )
private

InputBuffer callback: Called if a key was pressed that moves the input cursor the left (usually [arrow left]).

void orxonox::Shell::cursorRight ( )
private

InputBuffer callback: Called if a key was pressed that moves the input cursor the right (usually [arrow right]).

void orxonox::Shell::deleteChar ( )
private

InputBuffer callback: Called if a key was pressed that deletes the character after the cursor (usually [delete]).

void orxonox::Shell::devModeChanged ( bool  value)
overrideprivatevirtual

Called upon changes in the development mode (by Core) Behaviour details see Core::devModeChanged.

Implements orxonox::DevModeListener.

void orxonox::Shell::execute ( )
private

InputBuffer callback: Called if a key was pressed that executes a command (usually [return]).

void orxonox::Shell::exit ( )
private

InputBuffer callback: Called if a key was pressed that clears the text in the input buffer or closes the shell (usually [esc]).

static unsigned int orxonox::Shell::getCacheSize ( )
inlinestatic

Returns the cache size that is actually used in CommandExecutor, but placed here for better readability of the config file.

unsigned int orxonox::Shell::getCursorPosition ( ) const

Returns the current position of the cursor in the input buffer.

Shell::LineList::const_iterator orxonox::Shell::getEndIterator ( ) const

Returns the end() iterator of the list of output-lines.

const std::string & orxonox::Shell::getFromHistory ( ) const
private

Returns a command from the history of entered commands (usually the most recent history entry, but the user can scroll through the history).

const std::string & orxonox::Shell::getInput ( ) const

Returns the current content of the input buffer (the text which was entered by the user)

InputBuffer* orxonox::Shell::getInputBuffer ( )
inline

Returns the input buffer which is needed by the user to enter text into the shell.

Shell::LineList::const_iterator orxonox::Shell::getNewestLineIterator ( ) const

Returns an iterator to the newest line of output (except if the user is currently scrolling through the output).

unsigned int orxonox::Shell::getNumLines ( ) const
inline

Returns the number of output-lines that are displayed in the shell.

unsigned int orxonox::Shell::getScrollPosition ( ) const
inline

Returns the line which is currently viewed if the user scrolls through the older output-lines in the shell.

void orxonox::Shell::hintAndComplete ( )
private

InputBuffer callback: Called if a key was pressed that shows hints and completes a command (usually [tab]).

void orxonox::Shell::historyDown ( )
private

InputBuffer callback: Called if a key was pressed that scrolls downwards through the history of entered commands (usually [arrow down]).

void orxonox::Shell::historySearchDown ( )
private

InputBuffer callback: Called if a key was pressed that searches downwards through the history for a command stat starts like the one the user is currently typing (usually [page down]). Only if the shell is not scrollable.

void orxonox::Shell::historySearchUp ( )
private

InputBuffer callback: Called if a key was pressed that searches upwards through the history for a command stat starts like the one the user is currently typing (usually [page up]). Only if the shell is not scrollable.

void orxonox::Shell::historyUp ( )
private

InputBuffer callback: Called if a key was pressed that scrolls upwards through the history of entered commands (usually [arrow up]).

void orxonox::Shell::inputChanged ( )
private

InputBuffer callback: Called if the input changes.

Shell& orxonox::Shell::operator= ( const Shell )
privatedelete
void orxonox::Shell::printLine ( const std::string &  line,
OutputLevel  level 
)
overrideprivatevirtual

Inherited from BaseWriter (LogListener), called if a new line of output was sent.

Implements orxonox::BaseWriter.

void orxonox::Shell::registerListener ( ShellListener listener)

Registers a shell listener which listens for changes in this shell.

void orxonox::Shell::scrollDown ( )
private

InputBuffer callback: Called if a key was pressed that scrolls downwards through the output history (usually [page down]). Only if the shell is scrollable.

void orxonox::Shell::scrollUp ( )
private

InputBuffer callback: Called if a key was pressed that scrolls upwards through the output history (usually [page up]). Only if the shell is scrollable.

void orxonox::Shell::setConfigValues ( )

Defines the config values.

void orxonox::Shell::setCursorPosition ( unsigned int  cursor)

Changes the position of the cursor in the input buffer.

void orxonox::Shell::unregisterListener ( ShellListener listener)

Unregisters a shell listener.

template<void(ShellListener::*)() F>
void orxonox::Shell::updateListeners ( )
inlineprivate

Iterates through all registered shell listeners and calls the function F.

Member Data Documentation

const bool orxonox::Shell::bScrollable_
private

If true, the user can scroll through the output-lines.

unsigned int orxonox::Shell::cacheSize_s
staticprivate

The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is not configurable.

std::vector<std::string> orxonox::Shell::commandHistory_
private

The history of commands that were entered by the user.

unsigned int orxonox::Shell::historyOffset_
private

The command history is a circular buffer, this variable defines the current write-offset.

unsigned int orxonox::Shell::historyPosition_
private

If the user scrolls through the history of entered commands (stored in commandHistory_), this contains the currently viewed history entry.

InputBuffer* orxonox::Shell::inputBuffer_
private

The input buffer that is needed by the user to enter text.

std::list<ShellListener*> orxonox::Shell::listeners_
private

The registered shell listeners.

unsigned int orxonox::Shell::maxHistoryLength_
private

The maximum number of saved commands.

LineList orxonox::Shell::outputLines_
private

A list of all output-lines that were displayed in the shell so far.

LineList::const_iterator orxonox::Shell::scrollIterator_
private

An iterator to an entry of the list of output-lines, changes if the user scrolls through the output in the shell.

unsigned int orxonox::Shell::scrollPosition_
private

The number of the line that is currently being referenced by scrollIterator_.


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