]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/ScriptingDock.cxx
4ec7f3bd3be451269b6ffefef377df1e7d6ce0bb
[frida/frida.git] / src / gui / widgets / ScriptingDock.cxx
1 #include "ScriptingDock.hxx"
2 #include "FridaDock.hxx"
3
4 #include "bindings/Interpreter.hxx"
5
6 #include <sstream>
7
8 namespace {
9 class ScriptingLineEdit : public QObject, public QLineEdit {
10 public:
11 void keyPressEvent(QKeyEvent* event) {
12 if (event->key() == Qt::Key_Up) {
13 setText(backlog);
14 }
15 QLineEdit::keyPressEvent(event);
16 }
17
18 void clear() {
19 backlog = text();
20 QLineEdit::clear();
21 }
22 private:
23 QString backlog;
24 };
25 }
26
27 ScriptingDock::ScriptingDock(Interpreter* interpreter, FridaDock* parent)
28 : QWidget(parent)
29 , logger(log4cxx::Logger::getLogger("gui.ScriptingDock"))
30 , interpreter(interpreter) {
31 setLayout(layout = new QGridLayout);
32 layout->addWidget(browser = new QTextBrowser, 0, 0, 1, 0);
33 layout->addWidget(line = new ScriptingLineEdit, 1, 0);
34 layout->addWidget(button = new QPushButton(tr("Evaluate")), 1, 1);
35 connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
36 connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
37 }
38
39
40 void ScriptingDock::doEvaluate() {
41 std::stringstream stdout, stderr;
42 std::string result;
43 QString output;
44 QString text = line->text();
45
46 ((ScriptingLineEdit*)line)->clear();
47 LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
48 browser->append(QString("> ") + text);
49
50 interpreter->evaluate(text.toStdString(), stdout, stderr, result);
51
52 output = stdout.str().c_str();
53 if (output.endsWith("\n")) output.chop(1);
54 if (output != "") browser->append(output);
55
56 output = stderr.str().c_str();
57 if (output.endsWith("\n")) output.chop(1);
58 if (output != "") browser->append(output);
59
60 browser->append(result.c_str());
61 }