[Orxonox-commit 1292] r6010 - in code/branches/console/src: libraries/core libraries/core/input orxonox/overlays
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Oct 31 23:13:52 CET 2009
Author: rgrieder
Date: 2009-10-31 23:13:52 +0100 (Sat, 31 Oct 2009)
New Revision: 6010
Modified:
code/branches/console/src/libraries/core/IOConsole.cc
code/branches/console/src/libraries/core/IOConsole.h
code/branches/console/src/libraries/core/Shell.cc
code/branches/console/src/libraries/core/Shell.h
code/branches/console/src/libraries/core/input/InputPrereqs.h
code/branches/console/src/orxonox/overlays/InGameConsole.cc
Log:
Sorted out some small stuff in the Shell and hopefully fixed IOConsole problems (flickering and too much output).
Modified: code/branches/console/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.cc 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/libraries/core/IOConsole.cc 2009-10-31 22:13:52 UTC (rev 6010)
@@ -49,7 +49,6 @@
namespace orxonox
{
IOConsole* IOConsole::singletonPtr_s = NULL;
- const std::string promptString_g = "orxonox>";
#ifdef ORXONOX_PLATFORM_UNIX
@@ -64,10 +63,11 @@
}
IOConsole::IOConsole()
- : shell_(new Shell("IOConsole", false))
+ : shell_(new Shell("IOConsole", false, true))
, buffer_(shell_->getInputBuffer())
, originalTerminalSettings_(new termios())
, bStatusPrinted_(false)
+ , promptString_("orxonox> ")
{
this->setTerminalMode();
this->shell_->registerListener(this);
@@ -142,9 +142,9 @@
else if (escapeSequence == "4~" || escapeSequence == "F")
this->buffer_->buttonPressed(KeyEvent(KeyCode::End, 0, 0));
else if (escapeSequence == "5~")
- this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageUp, 0, 0));
+ this->buffer_->buttonPressed(KeyEvent(KeyCode::PageUp, 0, 0));
else if (escapeSequence == "6~")
- this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageDown, 0, 0));
+ this->buffer_->buttonPressed(KeyEvent(KeyCode::PageDown, 0, 0));
else
// Waiting for sequence to complete
// If the user presses ESC and then '[' or 'O' while the loop is not
@@ -191,6 +191,7 @@
std::cout << "\033[" << (this->bStatusPrinted_ ? this->statusLineWidths_.size() : 0) << "F\033[J";
this->printStatusLines();
this->printInputLine();
+ std::cout.flush();
}
void IOConsole::printLogText(const std::string& text)
@@ -226,7 +227,6 @@
// Reset colour to white
// std::cout << "\033[37m";
- std::cout.flush();
}
void IOConsole::printInputLine()
@@ -243,7 +243,6 @@
std::cout << "\033[u";
if (this->buffer_->getCursorPosition() > 0)
std::cout << "\033[" << this->buffer_->getCursorPosition() << "C";
- std::cout.flush();
}
void IOConsole::printStatusLines()
@@ -258,7 +257,6 @@
return;
}
std::cout << "Status" << std::endl;
- std::cout.flush();
this->bStatusPrinted_ = true;
}
}
@@ -331,6 +329,10 @@
{
}
+ void IOConsole::printStatusLines()
+ {
+ }
+
#endif /* ORXONOX_PLATFORM_UNIX */
// ###############################
@@ -377,6 +379,7 @@
std::cout << std::endl;
this->printStatusLines();
this->printInputLine();
+ std::cout.flush();
}
/**
@@ -386,6 +389,7 @@
void IOConsole::inputChanged()
{
this->printInputLine();
+ std::cout.flush();
}
/**
@@ -395,6 +399,7 @@
void IOConsole::cursorChanged()
{
this->printInputLine();
+ std::cout.flush();
}
/**
@@ -403,11 +408,7 @@
*/
void IOConsole::executed()
{
- // Move cursor the beginning of the line
- std::cout << "\033[1G";
- // Print command so the user knows what he has typed
- std::cout << promptString_g << this->shell_->getInput() << std::endl;
- this->printInputLine();
+ this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());
}
Modified: code/branches/console/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.h 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/libraries/core/IOConsole.h 2009-10-31 22:13:52 UTC (rev 6010)
@@ -76,6 +76,7 @@
bool bStatusPrinted_;
std::vector<unsigned> statusLineWidths_;
unsigned int statusLineMaxWidth_;
+ const std::string promptString_;
static const unsigned minOutputLines_ = 3;
static IOConsole* singletonPtr_s;
Modified: code/branches/console/src/libraries/core/Shell.cc
===================================================================
--- code/branches/console/src/libraries/core/Shell.cc 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/libraries/core/Shell.cc 2009-10-31 22:13:52 UTC (rev 6010)
@@ -22,7 +22,7 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Reto Grieder
*
*/
@@ -43,10 +43,11 @@
SetConsoleCommandShortcut(OutputHandler, info);
SetConsoleCommandShortcut(OutputHandler, debug);
- Shell::Shell(const std::string& consoleName, bool bScrollable)
- : inputBuffer_(new InputBuffer())
- , OutputListener(consoleName)
+ Shell::Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel)
+ : OutputListener(consoleName)
+ , inputBuffer_(new InputBuffer())
, consoleName_(consoleName)
+ , bPrependOutputLevel_(bPrependOutputLevel)
, bScrollable_(bScrollable)
{
RegisterRootObject(Shell);
@@ -55,10 +56,9 @@
this->maxHistoryLength_ = 100;
this->historyPosition_ = 0;
this->historyOffset_ = 0;
- this->finishedLastLine_ = true;
- this->bAddOutputLevel_ = false;
+ this->bFinishedLastLine_ = true;
- this->clearLines();
+ this->clearOutput();
this->configureInputBuffer();
// Get a config file for the command history
@@ -130,23 +130,29 @@
void Shell::configureInputBuffer()
{
this->inputBuffer_->registerListener(this, &Shell::inputChanged, true);
- this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
- this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false);
- this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true);
- this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
- this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true);
- this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete);
- this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape
- this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right);
- this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left);
- this->inputBuffer_->registerListener(this, &Shell::cursor_end, KeyCode::End);
- this->inputBuffer_->registerListener(this, &Shell::cursor_home, KeyCode::Home);
- this->inputBuffer_->registerListener(this, &Shell::history_up, KeyCode::Up);
- this->inputBuffer_->registerListener(this, &Shell::history_down, KeyCode::Down);
- this->inputBuffer_->registerListener(this, &Shell::scroll_up, KeyCode::PageUp);
- this->inputBuffer_->registerListener(this, &Shell::scroll_down, KeyCode::PageDown);
- this->inputBuffer_->registerListener(this, &Shell::history_search_up, KeyCode::AltPageUp);
- this->inputBuffer_->registerListener(this, &Shell::history_search_down, KeyCode::AltPageDown);
+ this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
+ this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false);
+ this->inputBuffer_->registerListener(this, &Shell::hintAndComplete, '\t', true);
+ this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
+ this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true);
+ this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape
+ this->inputBuffer_->registerListener(this, &Shell::deleteChar, KeyCode::Delete);
+ this->inputBuffer_->registerListener(this, &Shell::cursorRight, KeyCode::Right);
+ this->inputBuffer_->registerListener(this, &Shell::cursorLeft, KeyCode::Left);
+ this->inputBuffer_->registerListener(this, &Shell::cursorEnd, KeyCode::End);
+ this->inputBuffer_->registerListener(this, &Shell::cursorHome, KeyCode::Home);
+ this->inputBuffer_->registerListener(this, &Shell::historyUp, KeyCode::Up);
+ this->inputBuffer_->registerListener(this, &Shell::historyDown, KeyCode::Down);
+ if (this->bScrollable_)
+ {
+ this->inputBuffer_->registerListener(this, &Shell::scrollUp, KeyCode::PageUp);
+ this->inputBuffer_->registerListener(this, &Shell::scrollDown, KeyCode::PageDown);
+ }
+ else
+ {
+ this->inputBuffer_->registerListener(this, &Shell::historySearchUp, KeyCode::PageUp);
+ this->inputBuffer_->registerListener(this, &Shell::historySearchDown, KeyCode::PageDown);
+ }
}
/*
@@ -155,9 +161,9 @@
Shell& instance = Shell::getInstance();
for (unsigned int i = instance.historyOffset_; i < instance.commandHistory_.size(); ++i)
- instance.addLine(instance.commandHistory_[i], -1);
+ instance.addOutputLine(instance.commandHistory_[i], -1);
for (unsigned int i = 0; i < instance.historyOffset_; ++i)
- instance.addLine(instance.commandHistory_[i], -1);
+ instance.addOutputLine(instance.commandHistory_[i], -1);
}
*/
@@ -183,26 +189,20 @@
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::setInput(const std::string& input)
+ void Shell::addOutputLine(const std::string& line, int level)
{
- this->inputBuffer_->set(input);
- this->inputChanged();
- }
-
- void Shell::addLine(const std::string& line, int level)
- {
if (level <= this->softDebugLevel_)
this->outputLines_.push_front(line);
this->updateListeners<&ShellListener::lineAdded>();
}
- void Shell::clearLines()
+ void Shell::clearOutput()
{
this->outputLines_.clear();
this->scrollIterator_ = this->outputLines_.begin();
this->scrollPosition_ = 0;
- this->finishedLastLine_ = true;
+ this->bFinishedLastLine_ = true;
this->updateListeners<&ShellListener::linesChanged>();
}
@@ -255,9 +255,9 @@
if (!newline && output == "")
break;
- if (this->finishedLastLine_)
+ if (this->bFinishedLastLine_)
{
- if (this->bAddOutputLevel_)
+ if (this->bPrependOutputLevel_)
output.insert(0, 1, static_cast<char>(level));
this->outputLines_.push_front(output);
@@ -267,7 +267,7 @@
else
this->scrollIterator_ = this->outputLines_.begin();
- this->finishedLastLine_ = newline;
+ this->bFinishedLastLine_ = newline;
if (!this->scrollPosition_)
{
@@ -277,13 +277,30 @@
else
{
(*this->outputLines_.begin()) += output;
- this->finishedLastLine_ = newline;
+ this->bFinishedLastLine_ = newline;
this->updateListeners<&ShellListener::onlyLastLineChanged>();
}
} while (newline);
}
+ void Shell::clearInput()
+ {
+ this->inputBuffer_->clear();
+ this->historyPosition_ = 0;
+ this->updateListeners<&ShellListener::inputChanged>();
+ this->updateListeners<&ShellListener::cursorChanged>();
+ }
+
+ void Shell::setPromptPrefix(const std::string& str)
+ {
+ }
+
+
+ // ##########################################
+ // ### InputBuffer callback functions ###
+ // ##########################################
+
void Shell::inputChanged()
{
this->updateListeners<&ShellListener::inputChanged>();
@@ -296,15 +313,15 @@
this->updateListeners<&ShellListener::executed>();
if (!CommandExecutor::execute(this->inputBuffer_->get()))
- this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
+ this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
- this->clear();
+ this->clearInput();
}
- void Shell::hintandcomplete()
+ void Shell::hintAndComplete()
{
this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get()));
- this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
+ this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
this->inputChanged();
}
@@ -316,45 +333,52 @@
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::deletechar()
+ void Shell::exit()
{
- this->inputBuffer_->removeAtCursor();
- this->updateListeners<&ShellListener::inputChanged>();
+ if (this->inputBuffer_->getSize() > 0)
+ {
+ this->clearInput();
+ return;
+ }
+
+ this->clearInput();
+ this->scrollPosition_ = 0;
+ this->scrollIterator_ = this->outputLines_.begin();
+
+ this->updateListeners<&ShellListener::exit>();
}
- void Shell::clear()
+ void Shell::deleteChar()
{
- this->inputBuffer_->clear();
- this->historyPosition_ = 0;
+ this->inputBuffer_->removeAtCursor();
this->updateListeners<&ShellListener::inputChanged>();
- this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::cursor_right()
+ void Shell::cursorRight()
{
this->inputBuffer_->increaseCursor();
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::cursor_left()
+ void Shell::cursorLeft()
{
this->inputBuffer_->decreaseCursor();
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::cursor_end()
+ void Shell::cursorEnd()
{
this->inputBuffer_->setCursorToEnd();
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::cursor_home()
+ void Shell::cursorHome()
{
this->inputBuffer_->setCursorToBegin();
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::history_up()
+ void Shell::historyUp()
{
if (this->historyPosition_ < this->commandHistory_.size())
{
@@ -363,7 +387,7 @@
}
}
- void Shell::history_down()
+ void Shell::historyDown()
{
if (this->historyPosition_ > 0)
{
@@ -372,12 +396,12 @@
}
}
- void Shell::history_search_up()
+ void Shell::historySearchUp()
{
if (this->historyPosition_ == this->historyOffset_)
return;
unsigned int cursorPosition = this->getCursorPosition();
- std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position
+ std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until the cursor position
for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++)
{
if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive
@@ -390,12 +414,12 @@
}
}
- void Shell::history_search_down()
+ void Shell::historySearchDown()
{
if (this->historyPosition_ == 0)
return;
unsigned int cursorPosition = this->getCursorPosition();
- std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$
+ std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning
for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--)
{
if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$
@@ -408,7 +432,7 @@
}
}
- void Shell::scroll_up()
+ void Shell::scrollUp()
{
if (this->scrollIterator_ != this->outputLines_.end())
{
@@ -419,7 +443,7 @@
}
}
- void Shell::scroll_down()
+ void Shell::scrollDown()
{
if (this->scrollIterator_ != this->outputLines_.begin())
{
@@ -429,19 +453,4 @@
this->updateListeners<&ShellListener::linesChanged>();
}
}
-
- void Shell::exit()
- {
- if (this->inputBuffer_->getSize() > 0)
- {
- this->clear();
- return;
- }
-
- this->clear();
- this->scrollPosition_ = 0;
- this->scrollIterator_ = this->outputLines_.begin();
-
- this->updateListeners<&ShellListener::exit>();
- }
}
Modified: code/branches/console/src/libraries/core/Shell.h
===================================================================
--- code/branches/console/src/libraries/core/Shell.h 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/libraries/core/Shell.h 2009-10-31 22:13:52 UTC (rev 6010)
@@ -22,7 +22,7 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Reto Grieder
*
*/
@@ -60,11 +60,12 @@
virtual void exit() {}
};
+
class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
{
public:
- Shell(const std::string& consoleName, bool bScrollable);
- virtual ~Shell();
+ Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false);
+ ~Shell();
void setConfigValues();
void commandHistoryOffsetChanged();
@@ -80,53 +81,50 @@
inline unsigned int getCursorPosition() const
{ return this->inputBuffer_->getCursorPosition(); }
- void setInput(const std::string& input);
-
- inline void clearInput()
- { this->setInput(""); }
inline std::string getInput() const
{ return this->inputBuffer_->get(); }
std::list<std::string>::const_iterator getNewestLineIterator() const;
std::list<std::string>::const_iterator getEndIterator() const;
- void addLine(const std::string& line, int level = 0);
- void clearLines();
+ void addOutputLine(const std::string& line, int level = 0);
+ void clearOutput();
inline unsigned int getNumLines() const
{ return this->outputLines_.size(); }
inline unsigned int getScrollPosition() const
{ return this->scrollPosition_; }
- inline void addOutputLevel(bool bAddOutputLevel)
- { this->bAddOutputLevel_ = bAddOutputLevel; }
+ inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
+ void setPromptPrefix(const std::string& str);
private:
Shell(const Shell& other);
- void configureInputBuffer();
-
void addToHistory(const std::string& command);
std::string getFromHistory() const;
+ void clearInput();
+ // OutputListener
+ void outputChanged(int level);
- virtual void outputChanged(int level);
+ void configureInputBuffer();
+ // InputBuffer callbacks
void inputChanged();
void execute();
- void hintandcomplete();
+ void hintAndComplete();
void backspace();
- void deletechar();
- void clear();
- void cursor_right();
- void cursor_left();
- void cursor_end();
- void cursor_home();
- void history_up();
- void history_down();
- void history_search_up();
- void history_search_down();
- void scroll_up();
- void scroll_down();
+ void deleteChar();
+ void cursorRight();
+ void cursorLeft();
+ void cursorEnd();
+ void cursorHome();
+ void historyUp();
+ void historyDown();
+ void historySearchUp();
+ void historySearchDown();
+ void scrollUp();
+ void scrollDown();
void exit();
template <void (ShellListener::*F)()>
@@ -137,23 +135,25 @@
}
std::list<ShellListener*> listeners_;
- InputBuffer* inputBuffer_;
- std::stringstream outputBuffer_;
- bool finishedLastLine_;
- std::list<std::string> outputLines_;
+ InputBuffer* inputBuffer_;
+ std::stringstream outputBuffer_;
+ bool bFinishedLastLine_;
+ std::list<std::string> outputLines_;
std::list<std::string>::const_iterator scrollIterator_;
- unsigned int scrollPosition_;
- unsigned int historyPosition_;
- bool bAddOutputLevel_;
- ConfigFileType commandHistoryConfigFileType_;
- const std::string consoleName_;
- const bool bScrollable_;
+ unsigned int scrollPosition_;
+ unsigned int historyPosition_;
+ ConfigFileType commandHistoryConfigFileType_;
+ std::string promptPrefix_;
+ const std::string consoleName_;
+ const bool bPrependOutputLevel_;
+ const bool bScrollable_;
+
// Config values
- unsigned int maxHistoryLength_;
- unsigned int historyOffset_;
- std::vector<std::string> commandHistory_;
- int softDebugLevel_;
+ unsigned int maxHistoryLength_;
+ unsigned int historyOffset_;
+ std::vector<std::string> commandHistory_;
+ int softDebugLevel_;
};
}
Modified: code/branches/console/src/libraries/core/input/InputPrereqs.h
===================================================================
--- code/branches/console/src/libraries/core/input/InputPrereqs.h 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/libraries/core/input/InputPrereqs.h 2009-10-31 22:13:52 UTC (rev 6010)
@@ -178,13 +178,11 @@
Home = OIS::KC_HOME, // Home on arrow keypad
Up = OIS::KC_UP, // UpArrow on arrow keypad
PageUp = OIS::KC_PGUP, // PgUp on arrow keypad
- AltPageUp = OIS::KC_PGUP+1, // Alternative PgUp for the IOConsole
Left = OIS::KC_LEFT, // LeftArrow on arrow keypad
Right = OIS::KC_RIGHT, // RightArrow on arrow keypad
End = OIS::KC_END, // End on arrow keypad
Down = OIS::KC_DOWN, // DownArrow on arrow keypad
PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad
- AltPageDown = OIS::KC_END-1, // Alternative PgUp for IOConsole
Insert = OIS::KC_INSERT, // Insert on arrow keypad
Delete = OIS::KC_DELETE, // Delete on arrow keypad
LeftWindows = OIS::KC_LWIN, // Left Windows key
@@ -287,11 +285,11 @@
"Home",
"UP",
"PageUp",
- "", // used for AltPageUp
+ "",
"Left",
"",
"Right",
- "", // used for AltPageDown
+ "",
"End", "Down", "PageDown", "Insert", "Delete",
"","","","","","","",
"LeftWindows", "RightWindows", "Apps",
Modified: code/branches/console/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-10-30 22:25:26 UTC (rev 6009)
+++ code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-10-31 22:13:52 UTC (rev 6010)
@@ -67,7 +67,7 @@
@brief Constructor: Creates and initializes the InGameConsole.
*/
InGameConsole::InGameConsole()
- : shell_(new Shell("InGameConsole", true))
+ : shell_(new Shell("InGameConsole", true, true))
, consoleOverlay_(0)
, consoleOverlayContainer_(0)
, consoleOverlayNoise_(0)
@@ -255,8 +255,6 @@
// we take -1.2 because the border makes the panel bigger
this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
- this->shell_->addOutputLevel(true);
-
COUT(4) << "Info: InGameConsole initialized" << std::endl;
}
More information about the Orxonox-commit
mailing list