Commit 47b2dbf0 authored by lm's avatar lm

Added command history

parent af9f2479
...@@ -58,6 +58,7 @@ DebugConsole::DebugConsole(QWidget *parent) : ...@@ -58,6 +58,7 @@ DebugConsole::DebugConsole(QWidget *parent) :
lowpassDataRate(0.0f), lowpassDataRate(0.0f),
dataRateThreshold(500), dataRateThreshold(500),
autoHold(true), autoHold(true),
commandIndex(0),
m_ui(new Ui::DebugConsole) m_ui(new Ui::DebugConsole)
{ {
// Setup basic user interface // Setup basic user interface
...@@ -471,6 +472,12 @@ void DebugConsole::appendSpecialSymbol() ...@@ -471,6 +472,12 @@ void DebugConsole::appendSpecialSymbol()
void DebugConsole::sendBytes() void DebugConsole::sendBytes()
{ {
// Store command history
commandHistory.append(m_ui->sendText->text());
// Since text was just sent, we're at position commandHistory.length()
// which is the current text
commandIndex = commandHistory.length();
if (!m_ui->sentText->isVisible()) if (!m_ui->sentText->isVisible())
{ {
m_ui->sentText->setVisible(true); m_ui->sentText->setVisible(true);
...@@ -678,18 +685,12 @@ void DebugConsole::keyPressEvent(QKeyEvent * event) ...@@ -678,18 +685,12 @@ void DebugConsole::keyPressEvent(QKeyEvent * event)
{ {
if (event->key() == Qt::Key_Up) if (event->key() == Qt::Key_Up)
{ {
qDebug() << "UP KEY PRESSED";
cycleCommandHistory(true); cycleCommandHistory(true);
} }
else if (event->key() == Qt::Key_Down) else if (event->key() == Qt::Key_Down)
{ {
qDebug() << "DOWN KEY PRESSED";
cycleCommandHistory(false); cycleCommandHistory(false);
} }
else if (event->key() == Qt::Key_Enter)
{
this->sendBytes();
}
else else
{ {
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
...@@ -698,8 +699,11 @@ void DebugConsole::keyPressEvent(QKeyEvent * event) ...@@ -698,8 +699,11 @@ void DebugConsole::keyPressEvent(QKeyEvent * event)
void DebugConsole::cycleCommandHistory(bool up) void DebugConsole::cycleCommandHistory(bool up)
{ {
// Only cycle if there is a history
if (commandHistory.length() > 0)
{
// Store current command if we're not in history yet // Store current command if we're not in history yet
if (commandIndex == commandHistory.length()) if (commandIndex == commandHistory.length() && up)
{ {
currCommand = m_ui->sendText->text(); currCommand = m_ui->sendText->text();
} }
...@@ -727,12 +731,23 @@ void DebugConsole::cycleCommandHistory(bool up) ...@@ -727,12 +731,23 @@ void DebugConsole::cycleCommandHistory(bool up)
} }
// Restore current command if we went out of history
if (commandIndex == commandHistory.length())
{
m_ui->sendText->setText(currCommand);
}
// If we are too far down or too far up, wrap around to current command // If we are too far down or too far up, wrap around to current command
if (commandIndex < 0 || commandIndex > commandHistory.length()) if (commandIndex < 0 || commandIndex > commandHistory.length())
{ {
commandIndex = commandHistory.length(); commandIndex = commandHistory.length();
m_ui->sendText->setText(currCommand); m_ui->sendText->setText(currCommand);
} }
// Bound the index
if (commandIndex < 0) commandIndex = 0;
if (commandIndex > commandHistory.length()) commandIndex = commandHistory.length();
}
} }
void DebugConsole::changeEvent(QEvent *e) void DebugConsole::changeEvent(QEvent *e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment