xoreos  0.0.5
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Common::ReadLine Class Reference

#include <readline.h>

Collaboration diagram for Common::ReadLine:
Collaboration graph
[legend]

Classes

struct  HistorySave
 

Public Member Functions

 ReadLine (size_t historySize)
 
 ~ReadLine ()
 
void historyIgnoreSpace (bool ignoreSpace)
 Don't save lines starting with a space. More...
 
void historyIgnoreDups (bool ignoreDups)
 Don't save lines matching the bottom of the history. More...
 
void historyEraseDups (bool eraseDups)
 Erase all lines matching the line to be saved. More...
 
void clearHistory ()
 Clear the input history. More...
 
void addCommand (const UString &command)
 Add a command that can be tab-completed. More...
 
void setArguments (const UString &command, const std::vector< UString > &arguments)
 Set the tab-completable arguments for a command. More...
 
void setArguments (const UString &command)
 Clear the tab-completable arguments for a command. More...
 
const UStringgetCurrentLine () const
 Return the current input line. More...
 
size_t getCursorPosition () const
 Return the current cursor position within the input line. More...
 
bool getOverwrite () const
 Return whether we're current in overwrite mode. More...
 
const std::vector< UString > & getCompleteHint (size_t &maxSize) const
 Return the current tab-completion hints. More...
 
void addInput (uint32 c)
 Add that character to the current input. More...
 
void addInput (const UString &str)
 Add that string to the current input. More...
 
bool processEvent (const Events::Event &event, UString &command)
 Process that given events. More...
 

Private Types

typedef std::set< UStringCommandSet
 
typedef std::map< UString, CommandSetArgumentSets
 

Private Member Functions

std::list< HistorySave >::iterator findHistorySave ()
 
void addCurrentLineToHistory ()
 
void updateHistory ()
 
void browseUp ()
 
void browseDown ()
 
void browseTop ()
 
void browseBottom ()
 
bool processKeyDown (const Events::Event &event, UString &command)
 
bool processTextInput (const Events::Event &event, UString &command)
 
void tabComplete ()
 
void tabComplete (const UString &prefix, const UString &input, const CommandSet &commands)
 
UString::iterator getCurrentPosition () const
 
size_t findLastWordStart (bool onlySpace=false) const
 
size_t findNextWordEnd (bool onlySpace=false) const
 

Static Private Member Functions

static bool isWordCharacter (uint32 c, bool onlySpace=false)
 
static UString findCommonSubstring (const std::list< UString > &strings)
 

Private Attributes

size_t _historySizeMax
 Max size of the history. More...
 
size_t _historySizeCurrent
 Current size of the history. More...
 
bool _historyIgnoreSpace
 Should we not remember input beginning with spaces? More...
 
bool _historyIgnoreDups
 Should we not remember duplicate lines? More...
 
bool _historyEraseDups
 Should we actively remove duplicate lines? More...
 
size_t _cursorPosition
 The current cursor position. More...
 
bool _overwrite
 Overwrite instead of insert? More...
 
UString _currentLine
 The current input line. More...
 
UString _currentLineBak
 The backupped input line while we're browsing the history. More...
 
std::list< UString_history
 The history of previous input lines. More...
 
std::list< UString >::iterator _historyPosition
 The current browsing position within the history. More...
 
std::list< HistorySave_historySave
 Saved copies of modified history lines. More...
 
CommandSet _commands
 All known tab-completable commands. More...
 
ArgumentSets _arguments
 All know tab-completable command arguments. More...
 
std::vector< UString_completeHint
 Current possible command candidates for the input line. More...
 
size_t _maxHintSize
 Max size of a current command candidates. More...
 

Detailed Description

Definition at line 40 of file readline.h.

Member Typedef Documentation

◆ ArgumentSets

Definition at line 99 of file readline.h.

◆ CommandSet

typedef std::set<UString> Common::ReadLine::CommandSet
private

Definition at line 98 of file readline.h.

Constructor & Destructor Documentation

◆ ReadLine()

Common::ReadLine::ReadLine ( size_t  historySize)

Definition at line 34 of file readline.cpp.

References _history, and _historyPosition.

◆ ~ReadLine()

Common::ReadLine::~ReadLine ( )

Definition at line 42 of file readline.cpp.

Member Function Documentation

◆ addCommand()

void Common::ReadLine::addCommand ( const UString command)

Add a command that can be tab-completed.

Definition at line 62 of file readline.cpp.

References _commands.

◆ addCurrentLineToHistory()

void Common::ReadLine::addCurrentLineToHistory ( )
private

◆ addInput() [1/2]

void Common::ReadLine::addInput ( uint32  c)

Add that character to the current input.

Definition at line 99 of file readline.cpp.

References _currentLine, _cursorPosition, _overwrite, getCurrentPosition(), Common::UString::insert(), Common::UString::replace(), and updateHistory().

Referenced by addInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addInput() [2/2]

void Common::ReadLine::addInput ( const UString str)

Add that string to the current input.

Definition at line 113 of file readline.cpp.

References addInput(), Common::UString::begin(), and Common::UString::end().

Here is the call graph for this function:

◆ browseBottom()

void Common::ReadLine::browseBottom ( )
private

Definition at line 443 of file readline.cpp.

References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ browseDown()

void Common::ReadLine::browseDown ( )
private

Definition at line 401 of file readline.cpp.

References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ browseTop()

void Common::ReadLine::browseTop ( )
private

Definition at line 421 of file readline.cpp.

References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ browseUp()

void Common::ReadLine::browseUp ( )
private

Definition at line 379 of file readline.cpp.

References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearHistory()

void Common::ReadLine::clearHistory ( )

Clear the input history.

Definition at line 57 of file readline.cpp.

References _history, and _historySizeCurrent.

◆ findCommonSubstring()

UString Common::ReadLine::findCommonSubstring ( const std::list< UString > &  strings)
staticprivate

Definition at line 528 of file readline.cpp.

References MIN().

Referenced by tabComplete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findHistorySave()

std::list< ReadLine::HistorySave >::iterator Common::ReadLine::findHistorySave ( )
private

Definition at line 305 of file readline.cpp.

References _historyPosition, and _historySave.

Referenced by addCurrentLineToHistory(), and updateHistory().

Here is the caller graph for this function:

◆ findLastWordStart()

size_t Common::ReadLine::findLastWordStart ( bool  onlySpace = false) const
private

Definition at line 568 of file readline.cpp.

References _currentLine, _cursorPosition, Common::UString::begin(), Common::UString::getPosition(), and isWordCharacter().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findNextWordEnd()

size_t Common::ReadLine::findNextWordEnd ( bool  onlySpace = false) const
private

Definition at line 590 of file readline.cpp.

References _currentLine, _cursorPosition, Common::UString::end(), Common::UString::getPosition(), and isWordCharacter().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCompleteHint()

const std::vector< UString > & Common::ReadLine::getCompleteHint ( size_t &  maxSize) const

Return the current tab-completion hints.

Definition at line 93 of file readline.cpp.

References _completeHint, and _maxHintSize.

◆ getCurrentLine()

const UString & Common::ReadLine::getCurrentLine ( ) const

Return the current input line.

Definition at line 81 of file readline.cpp.

References _currentLine.

◆ getCurrentPosition()

UString::iterator Common::ReadLine::getCurrentPosition ( ) const
private

Definition at line 301 of file readline.cpp.

References _currentLine, _cursorPosition, and Common::UString::getPosition().

Referenced by addInput(), processKeyDown(), and processTextInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCursorPosition()

size_t Common::ReadLine::getCursorPosition ( ) const

Return the current cursor position within the input line.

Definition at line 85 of file readline.cpp.

References _cursorPosition.

◆ getOverwrite()

bool Common::ReadLine::getOverwrite ( ) const

Return whether we're current in overwrite mode.

Definition at line 89 of file readline.cpp.

References _overwrite.

◆ historyEraseDups()

void Common::ReadLine::historyEraseDups ( bool  eraseDups)

Erase all lines matching the line to be saved.

Definition at line 53 of file readline.cpp.

References _historyEraseDups.

◆ historyIgnoreDups()

void Common::ReadLine::historyIgnoreDups ( bool  ignoreDups)

Don't save lines matching the bottom of the history.

Definition at line 49 of file readline.cpp.

References _historyIgnoreDups.

◆ historyIgnoreSpace()

void Common::ReadLine::historyIgnoreSpace ( bool  ignoreSpace)

Don't save lines starting with a space.

Definition at line 45 of file readline.cpp.

References _historyIgnoreSpace.

◆ isWordCharacter()

bool Common::ReadLine::isWordCharacter ( uint32  c,
bool  onlySpace = false 
)
staticprivate

Definition at line 561 of file readline.cpp.

References Common::UString::isAlNum(), and Common::UString::isASCII().

Referenced by findLastWordStart(), and findNextWordEnd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processEvent()

bool Common::ReadLine::processEvent ( const Events::Event event,
UString command 
)

Process that given events.

Depends on unicode translation to be turned on.

Parameters
eventThe event to process.
commandWhen enter was pressed, the command to be executed will be stored here.
Returns
true if the event was handled.

Definition at line 118 of file readline.cpp.

References _completeHint, _maxHintSize, Common::UString::clear(), Events::kEventKeyDown, Events::kEventTextInput, processKeyDown(), and processTextInput().

Here is the call graph for this function:

◆ processKeyDown()

bool Common::ReadLine::processKeyDown ( const Events::Event event,
UString command 
)
private

◆ processTextInput()

bool Common::ReadLine::processTextInput ( const Events::Event event,
UString command 
)
private

Definition at line 284 of file readline.cpp.

References _currentLine, _cursorPosition, _overwrite, Common::UString::empty(), EventMan, getCurrentPosition(), Common::UString::insert(), Common::UString::replace(), Common::UString::size(), and updateHistory().

Referenced by processEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setArguments() [1/2]

void Common::ReadLine::setArguments ( const UString command,
const std::vector< UString > &  arguments 
)

Set the tab-completable arguments for a command.

Definition at line 66 of file readline.cpp.

References _arguments.

◆ setArguments() [2/2]

void Common::ReadLine::setArguments ( const UString command)

Clear the tab-completable arguments for a command.

Definition at line 75 of file readline.cpp.

References _arguments.

◆ tabComplete() [1/2]

void Common::ReadLine::tabComplete ( )
private

Definition at line 457 of file readline.cpp.

References _arguments, _commands, _currentLine, Common::UString::end(), Common::UString::findFirst(), Common::UString::split(), and Common::UString::trimLeft().

Referenced by processKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tabComplete() [2/2]

void Common::ReadLine::tabComplete ( const UString prefix,
const UString input,
const CommandSet commands 
)
private

Definition at line 476 of file readline.cpp.

References _completeHint, _currentLine, _cursorPosition, _maxHintSize, findCommonSubstring(), MAX(), and Common::UString::size().

Here is the call graph for this function:

◆ updateHistory()

void Common::ReadLine::updateHistory ( )
private

Definition at line 314 of file readline.cpp.

References _currentLine, _history, _historyPosition, _historySave, and findHistorySave().

Referenced by addInput(), processKeyDown(), and processTextInput().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _arguments

ArgumentSets Common::ReadLine::_arguments
private

All know tab-completable command arguments.

Definition at line 127 of file readline.h.

Referenced by setArguments(), and tabComplete().

◆ _commands

CommandSet Common::ReadLine::_commands
private

All known tab-completable commands.

Definition at line 125 of file readline.h.

Referenced by addCommand(), and tabComplete().

◆ _completeHint

std::vector<UString> Common::ReadLine::_completeHint
private

Current possible command candidates for the input line.

Definition at line 130 of file readline.h.

Referenced by getCompleteHint(), processEvent(), and tabComplete().

◆ _currentLine

UString Common::ReadLine::_currentLine
private

◆ _currentLineBak

UString Common::ReadLine::_currentLineBak
private

The backupped input line while we're browsing the history.

Definition at line 114 of file readline.h.

Referenced by addCurrentLineToHistory(), browseBottom(), browseDown(), browseTop(), and browseUp().

◆ _cursorPosition

size_t Common::ReadLine::_cursorPosition
private

◆ _history

std::list<UString> Common::ReadLine::_history
private

The history of previous input lines.

Definition at line 117 of file readline.h.

Referenced by addCurrentLineToHistory(), browseBottom(), browseDown(), browseTop(), browseUp(), clearHistory(), ReadLine(), and updateHistory().

◆ _historyEraseDups

bool Common::ReadLine::_historyEraseDups
private

Should we actively remove duplicate lines?

Definition at line 107 of file readline.h.

Referenced by addCurrentLineToHistory(), and historyEraseDups().

◆ _historyIgnoreDups

bool Common::ReadLine::_historyIgnoreDups
private

Should we not remember duplicate lines?

Definition at line 106 of file readline.h.

Referenced by addCurrentLineToHistory(), and historyIgnoreDups().

◆ _historyIgnoreSpace

bool Common::ReadLine::_historyIgnoreSpace
private

Should we not remember input beginning with spaces?

Definition at line 105 of file readline.h.

Referenced by addCurrentLineToHistory(), and historyIgnoreSpace().

◆ _historyPosition

std::list<UString>::iterator Common::ReadLine::_historyPosition
private

The current browsing position within the history.

Definition at line 119 of file readline.h.

Referenced by addCurrentLineToHistory(), browseBottom(), browseDown(), browseTop(), browseUp(), findHistorySave(), ReadLine(), and updateHistory().

◆ _historySave

std::list<HistorySave> Common::ReadLine::_historySave
private

Saved copies of modified history lines.

Definition at line 122 of file readline.h.

Referenced by addCurrentLineToHistory(), findHistorySave(), and updateHistory().

◆ _historySizeCurrent

size_t Common::ReadLine::_historySizeCurrent
private

Current size of the history.

Definition at line 103 of file readline.h.

Referenced by addCurrentLineToHistory(), and clearHistory().

◆ _historySizeMax

size_t Common::ReadLine::_historySizeMax
private

Max size of the history.

Definition at line 102 of file readline.h.

Referenced by addCurrentLineToHistory().

◆ _maxHintSize

size_t Common::ReadLine::_maxHintSize
private

Max size of a current command candidates.

Definition at line 132 of file readline.h.

Referenced by getCompleteHint(), processEvent(), and tabComplete().

◆ _overwrite

bool Common::ReadLine::_overwrite
private

Overwrite instead of insert?

Definition at line 111 of file readline.h.

Referenced by addCurrentLineToHistory(), addInput(), browseBottom(), browseDown(), browseTop(), browseUp(), getOverwrite(), processKeyDown(), and processTextInput().


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