diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-23 16:40:17 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-23 16:40:17 +0100 |
commit | 8c78033ca7e59c44eb2886a3f8fe89c5b22ad114 (patch) | |
tree | d0248fe657feb5442a5bbd9d8e2abc499a51ab77 /akonadi2_cli/repl/replStates.cpp | |
parent | afba02ad5fc52acf84a18f67f38b6b75267a31c0 (diff) | |
download | sink-8c78033ca7e59c44eb2886a3f8fe89c5b22ad114.tar.gz sink-8c78033ca7e59c44eb2886a3f8fe89c5b22ad114.zip |
handle multiline, use Module::tokenize
Diffstat (limited to 'akonadi2_cli/repl/replStates.cpp')
-rw-r--r-- | akonadi2_cli/repl/replStates.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
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 | |||
81 | } | 81 | } |
82 | 82 | ||
83 | EvalState::EvalState(QState *parent) | 83 | EvalState::EvalState(QState *parent) |
84 | : QState(parent), | 84 | : QState(parent) |
85 | m_complete(false) | ||
86 | { | 85 | { |
87 | } | 86 | } |
88 | 87 | ||
@@ -90,29 +89,36 @@ void EvalState::onEntry(QEvent *event) | |||
90 | { | 89 | { |
91 | QStateMachine::SignalEvent *e = dynamic_cast<QStateMachine::SignalEvent*>(event); | 90 | QStateMachine::SignalEvent *e = dynamic_cast<QStateMachine::SignalEvent*>(event); |
92 | 91 | ||
93 | if (!e || e->arguments().isEmpty()) { | 92 | const QString command = e ? e->arguments()[0].toString() : QString(); |
94 | if (m_complete) { | 93 | |
95 | emit completed(); | 94 | if (command.isEmpty()) { |
96 | } else { | 95 | complete(); |
97 | emit continueInput(); | ||
98 | } | ||
99 | return; | 96 | return; |
100 | } | 97 | } |
101 | 98 | ||
102 | //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"'] | 99 | if (command.right(1) == "\\") { |
103 | const QString command = e->arguments()[0].toString(); | 100 | m_partial += " " + command.left(command.size() - 1); |
104 | 101 | continueInput(); | |
105 | if (!command.isEmpty()) { | 102 | } else { |
106 | m_complete = command.right(1) != "\\"; | 103 | m_partial += " " + command; |
107 | if (m_complete) { | 104 | complete(); |
108 | //emit output("Processing ... " + command); | ||
109 | const QStringList commands = command.split(" "); | ||
110 | Module::self()->run(commands); | ||
111 | emit completed(); | ||
112 | } | ||
113 | } | 105 | } |
114 | } | 106 | } |
115 | 107 | ||
108 | void EvalState::complete() | ||
109 | { | ||
110 | m_partial = m_partial.simplified(); | ||
111 | |||
112 | if (!m_partial.isEmpty()) { | ||
113 | //emit output("Processing ... " + command); | ||
114 | const QStringList commands = Module::tokenize(m_partial); | ||
115 | Module::self()->run(commands); | ||
116 | m_partial.clear(); | ||
117 | } | ||
118 | |||
119 | emit completed(); | ||
120 | } | ||
121 | |||
116 | PrintState::PrintState(QState *parent) | 122 | PrintState::PrintState(QState *parent) |
117 | : QState(parent) | 123 | : QState(parent) |
118 | { | 124 | { |