xoreos
0.0.5
|
#include <readline.h>
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 UString & | getCurrentLine () 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< UString > | CommandSet |
typedef std::map< UString, CommandSet > | ArgumentSets |
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... | |
Definition at line 40 of file readline.h.
|
private |
Definition at line 99 of file readline.h.
|
private |
Definition at line 98 of file readline.h.
Common::ReadLine::ReadLine | ( | size_t | historySize | ) |
Definition at line 34 of file readline.cpp.
References _history, and _historyPosition.
Common::ReadLine::~ReadLine | ( | ) |
Definition at line 42 of file readline.cpp.
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.
|
private |
Definition at line 330 of file readline.cpp.
References _currentLine, _currentLineBak, _cursorPosition, _history, _historyEraseDups, _historyIgnoreDups, _historyIgnoreSpace, _historyPosition, _historySave, _historySizeCurrent, _historySizeMax, _overwrite, Common::UString::begin(), Common::UString::clear(), Common::UString::empty(), and findHistorySave().
Referenced by processKeyDown().
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().
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().
|
private |
Definition at line 443 of file readline.cpp.
References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().
Referenced by processKeyDown().
|
private |
Definition at line 401 of file readline.cpp.
References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().
Referenced by processKeyDown().
|
private |
Definition at line 421 of file readline.cpp.
References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().
Referenced by processKeyDown().
|
private |
Definition at line 379 of file readline.cpp.
References _currentLine, _currentLineBak, _cursorPosition, _history, _historyPosition, _overwrite, and Common::UString::size().
Referenced by processKeyDown().
void Common::ReadLine::clearHistory | ( | ) |
Clear the input history.
Definition at line 57 of file readline.cpp.
References _history, and _historySizeCurrent.
Definition at line 528 of file readline.cpp.
References MIN().
Referenced by tabComplete().
|
private |
Definition at line 305 of file readline.cpp.
References _historyPosition, and _historySave.
Referenced by addCurrentLineToHistory(), and updateHistory().
|
private |
Definition at line 568 of file readline.cpp.
References _currentLine, _cursorPosition, Common::UString::begin(), Common::UString::getPosition(), and isWordCharacter().
Referenced by processKeyDown().
|
private |
Definition at line 590 of file readline.cpp.
References _currentLine, _cursorPosition, Common::UString::end(), Common::UString::getPosition(), and isWordCharacter().
Referenced by processKeyDown().
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.
const UString & Common::ReadLine::getCurrentLine | ( | ) | const |
|
private |
Definition at line 301 of file readline.cpp.
References _currentLine, _cursorPosition, and Common::UString::getPosition().
Referenced by addInput(), processKeyDown(), and processTextInput().
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.
bool Common::ReadLine::getOverwrite | ( | ) | const |
Return whether we're current in overwrite mode.
Definition at line 89 of file readline.cpp.
References _overwrite.
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.
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.
void Common::ReadLine::historyIgnoreSpace | ( | bool | ignoreSpace | ) |
Don't save lines starting with a space.
Definition at line 45 of file readline.cpp.
References _historyIgnoreSpace.
|
staticprivate |
Definition at line 561 of file readline.cpp.
References Common::UString::isAlNum(), and Common::UString::isASCII().
Referenced by findLastWordStart(), and findNextWordEnd().
bool Common::ReadLine::processEvent | ( | const Events::Event & | event, |
UString & | command | ||
) |
Process that given events.
Depends on unicode translation to be turned on.
event | The event to process. |
command | When enter was pressed, the command to be executed will be stored here. |
Definition at line 118 of file readline.cpp.
References _completeHint, _maxHintSize, Common::UString::clear(), Events::kEventKeyDown, Events::kEventTextInput, processKeyDown(), and processTextInput().
|
private |
Definition at line 132 of file readline.cpp.
References _currentLine, _cursorPosition, _overwrite, addCurrentLineToHistory(), Common::UString::begin(), browseBottom(), browseDown(), browseTop(), browseUp(), Common::UString::empty(), Common::UString::end(), Common::UString::erase(), findLastWordStart(), findNextWordEnd(), getCurrentPosition(), Common::UString::getPosition(), Common::UString::size(), tabComplete(), and updateHistory().
Referenced by processEvent().
|
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().
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.
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.
|
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().
|
private |
Definition at line 476 of file readline.cpp.
References _completeHint, _currentLine, _cursorPosition, _maxHintSize, findCommonSubstring(), MAX(), and Common::UString::size().
|
private |
Definition at line 314 of file readline.cpp.
References _currentLine, _history, _historyPosition, _historySave, and findHistorySave().
Referenced by addInput(), processKeyDown(), and processTextInput().
|
private |
All know tab-completable command arguments.
Definition at line 127 of file readline.h.
Referenced by setArguments(), and tabComplete().
|
private |
All known tab-completable commands.
Definition at line 125 of file readline.h.
Referenced by addCommand(), and tabComplete().
|
private |
Current possible command candidates for the input line.
Definition at line 130 of file readline.h.
Referenced by getCompleteHint(), processEvent(), and tabComplete().
|
private |
The current input line.
Definition at line 113 of file readline.h.
Referenced by addCurrentLineToHistory(), addInput(), browseBottom(), browseDown(), browseTop(), browseUp(), findLastWordStart(), findNextWordEnd(), getCurrentLine(), getCurrentPosition(), processKeyDown(), processTextInput(), tabComplete(), and updateHistory().
|
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().
|
private |
The current cursor position.
Definition at line 109 of file readline.h.
Referenced by addCurrentLineToHistory(), addInput(), browseBottom(), browseDown(), browseTop(), browseUp(), findLastWordStart(), findNextWordEnd(), getCurrentPosition(), getCursorPosition(), processKeyDown(), processTextInput(), and tabComplete().
|
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().
|
private |
Should we actively remove duplicate lines?
Definition at line 107 of file readline.h.
Referenced by addCurrentLineToHistory(), and historyEraseDups().
|
private |
Should we not remember duplicate lines?
Definition at line 106 of file readline.h.
Referenced by addCurrentLineToHistory(), and historyIgnoreDups().
|
private |
Should we not remember input beginning with spaces?
Definition at line 105 of file readline.h.
Referenced by addCurrentLineToHistory(), and historyIgnoreSpace().
|
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().
|
private |
Saved copies of modified history lines.
Definition at line 122 of file readline.h.
Referenced by addCurrentLineToHistory(), findHistorySave(), and updateHistory().
|
private |
Current size of the history.
Definition at line 103 of file readline.h.
Referenced by addCurrentLineToHistory(), and clearHistory().
|
private |
Max size of the history.
Definition at line 102 of file readline.h.
Referenced by addCurrentLineToHistory().
|
private |
Max size of a current command candidates.
Definition at line 132 of file readline.h.
Referenced by getCompleteHint(), processEvent(), and tabComplete().
|
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().