From 8c78033ca7e59c44eb2886a3f8fe89c5b22ad114 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 16:40:17 +0100 Subject: handle multiline, use Module::tokenize --- akonadi2_cli/repl/replStates.cpp | 44 +++++++++++++++++++++++----------------- akonadi2_cli/repl/replStates.h | 4 +++- 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'akonadi2_cli/repl') 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(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 -- cgit v1.2.3