[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [akonadi-next/feature/new_cli] akonadi2_cli/repl: handle multiline, use Module::tokenize
From: Aaron Seigo <aseigo () kde ! org>
Date: 2015-12-23 15:45:06
Message-ID: E1aBlb8-00076T-Aj () scm ! kde ! org
[Download RAW message or body]
Git commit 8c78033ca7e59c44eb2886a3f8fe89c5b22ad114 by Aaron Seigo.
Committed on 23/12/2015 at 15:40.
Pushed by aseigo into branch 'feature/new_cli'.
handle multiline, use Module::tokenize
M +25 -19 akonadi2_cli/repl/replStates.cpp
M +3 -1 akonadi2_cli/repl/replStates.h
http://commits.kde.org/akonadi-next/8c78033ca7e59c44eb2886a3f8fe89c5b22ad114
diff --git a/akonadi2_cli/repl/replStates.cpp b/akonadi2_cli/repl/replStates.cpp
index efa1353..314cca8 100644
--- a/akonadi2_cli/repl/replStates.cpp
+++ b/akonadi2_cli/repl/replStates.cpp
@@ -81,8 +81,7 @@ const char *UnfinishedReadState::prompt() const
}
EvalState::EvalState(QState *parent)
- : QState(parent),
- m_complete(false)
+ : QState(parent)
{
}
@@ -90,29 +89,36 @@ void EvalState::onEntry(QEvent *event)
{
QStateMachine::SignalEvent *e = dynamic_cast<QStateMachine::SignalEvent*>(event);
- if (!e || e->arguments().isEmpty()) {
- if (m_complete) {
- emit completed();
- } else {
- emit continueInput();
- }
+ const QString command = e ? e->arguments()[0].toString() : QString();
+
+ if (command.isEmpty()) {
+ complete();
return;
}
- //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']
- const QString command = e->arguments()[0].toString();
-
- if (!command.isEmpty()) {
- m_complete = command.right(1) != "\\";
- if (m_complete) {
- //emit output("Processing ... " + command);
- const QStringList commands = command.split(" ");
- Module::self()->run(commands);
- emit completed();
- }
+ if (command.right(1) == "\\") {
+ m_partial += " " + command.left(command.size() - 1);
+ continueInput();
+ } else {
+ m_partial += " " + command;
+ complete();
}
}
+void EvalState::complete()
+{
+ m_partial = m_partial.simplified();
+
+ if (!m_partial.isEmpty()) {
+ //emit output("Processing ... " + command);
+ const QStringList commands = Module::tokenize(m_partial);
+ Module::self()->run(commands);
+ m_partial.clear();
+ }
+
+ emit completed();
+}
+
PrintState::PrintState(QState *parent)
: QState(parent)
{
diff --git a/akonadi2_cli/repl/replStates.h b/akonadi2_cli/repl/replStates.h
index a019a37..a0d3f90 100644
--- a/akonadi2_cli/repl/replStates.h
+++ b/akonadi2_cli/repl/replStates.h
@@ -66,7 +66,9 @@ protected:
void onEntry(QEvent *event);
private:
- bool m_complete;
+ void complete();
+
+ QString m_partial;
};
class PrintState : public QState
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic