m_mainWindow->say(LOG_INFO, message);
}
+/**
+ * @brief CommandProcessor::tail
+ * @param args
+ */
+void CommandProcessor::tail(const QStringList& args)
+{
+ ReProgramArgs args2("Prints the last N lines of the files",
+ "tail -n 20 abc.txt xyz.txt");
+ args2.addInt("count", "number of lines to print", 'n', "lines", 10);
+ args2.addBool("quiet", "the filenames will be suppressed", 'q', "quiet", false);
+ args2.init(args, true);
+ if (args2.argCount() < 1)
+ args2.help("no files given");
+ else if (args2.argCount() == 1){
+ execTail(args2.arg(0), false, args2.getInt("count"));
+ } else {
+ for (int ix = 0; ix < args2.argCount(); ix++){
+ execTail(args2.arg(ix), ! args2.getBool("quiet"), args2.getInt("count"));
+ }
+ }
+}
+
+/**
+ * Issues the last N lines of a file.
+ *
+ * @param file the name of the file
+ * @param withName <code>true</code>: the filename is issued in front of the content
+ * @param count the number of lines to issue
+ */
+void CommandProcessor::execTail(const QString& file, bool withName, int count){
+ QByteArray file2 = I18N::s2b(file);
+ FILE* fp = fopen(file2, "rb");
+ if (fp == NULL){
+ printf("cannot open %s: %d", file2.constData(), errno);
+ } else {
+ if (withName)
+ printf("%s:\n", file2.constData());
+ QByteArray content;
+ int bufferSize = max(0x10000, count * 100) / 2;
+ int count2 = 0;
+ do {
+ bufferSize *= 2;
+ content.resize(bufferSize);
+ size_t pos = fseek(fp, -bufferSize, SEEK_END);
+ int pos2 = 0;
+ if ( (pos2 = fread(content.data(), 1, bufferSize, fp)) <= 0){
+ break;
+ } else {
+ content.resize(pos2);
+ const char* ptr = content.constData() + pos2 - 1;
+ const char* start = content.constData();
+ if (ptr > start && *ptr == '\n'){
+ ptr--;
+ }
+ int count2 = 0;
+ while(ptr > start && count2 < count){
+ if (*ptr-- == '\n')
+ count2--;
+ if (ptr == content.constData())
+ break;
+ }
+ if (count2 == count){
+ fputs(*ptr == '\n' ? ptr + 1 : ptr, fp);
+ }
+ }
+ } while(count2 != count);
+ fclose(fp);
+ }
+}
+
/**
* Executes one statement.
*
connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(onSave()));
connect(ui->pushButtonInterpolate, SIGNAL(clicked()), this, SLOT(onInterpolate()));
connect(ui->pushButtonExpand, SIGNAL(clicked()), this, SLOT(onExpand()));
+ connect(ui->lineEditCommand, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
+ connect(ui->listWidgetHistory, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
+ this, SLOT(onHistoryDoubleClicked(QListWidgetItem*)));
onLoad();
}
-
/**
* Destructor.
*/
}
}
+/**
+ * Handles a double click in the command history.
+ *
+ * @param item the current item
+ */
+void MainWindow::onHistoryDoubleClicked(QListWidgetItem* item){
+ ui->lineEditCommand->setText(item->text());
+}
+
/**
* Set GUI elements from the queue when the GUI timer is triggered.
*/
}
}
+/**
+ * Handles the RETURN button in the command line.
+ */
+void MainWindow::onReturnPressed(){
+ m_processor->interpret(ui->lineEditCommand->text());
+ toHistory(ui->lineEditCommand->text());
+ ui->lineEditCommand->clear();
+}
+
/**
* Executes the current commands.
*/
pos2++;
ui->plainTextEditResult->clear();
QString script = text.mid(pos1, pos2 - pos1 + 1);
- if (script.length() > 10 || script.trimmed().length() > 0)
+ if (script.length() > 10 || script.trimmed().length() > 0){
+ toHistory(script);
m_processor->interpret(script);
+ }
}
/**
ui->plainTextEditPad->toPlainText().toUtf8().constData());
}
+/**
+ * Inserts commands into the command history.
+ *
+ * @param commands the commands to insert
+ */
+void MainWindow::toHistory(const QString& commands)
+{
+ QStringList list = commands.split('\n');
+ for (int ix = 0; ix < list.count(); ix++){
+ ui->listWidgetHistory->addItem(list.at(ix));
+ }
+}
+
/**
* Writes a message.
*
<height>624</height>
</rect>
</property>
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
- <layout class="QVBoxLayout" name="verticalLayout_5">
+ <layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
- <widget class="QWidget" name="layoutWidget">
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Write command, try "help;"</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonRun">
- <property name="minimumSize">
- <size>
- <width>125</width>
- <height>0</height>
- </size>
- </property>
- <property name="text">
- <string>Run</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonSave">
- <property name="minimumSize">
- <size>
- <width>125</width>
- <height>0</height>
- </size>
- </property>
- <property name="text">
- <string>Save</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QPlainTextEdit" name="plainTextEditPad"/>
- </item>
- </layout>
- </widget>
- <widget class="QTabWidget" name="tabWidgetResult">
+ <widget class="QTabWidget" name="tabWidgetInput">
<property name="currentIndex">
- <number>2</number>
+ <number>0</number>
</property>
- <widget class="QWidget" name="tabList">
+ <property name="documentMode">
+ <bool>false</bool>
+ </property>
+ <property name="movable">
+ <bool>false</bool>
+ </property>
+ <widget class="QWidget" name="tabCommandLine">
<attribute name="title">
- <string>Result as list</string>
+ <string>Command line</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_3">
+ <layout class="QVBoxLayout" name="verticalLayout_8">
<item>
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Type command and <ENTER></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditCommand"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonClearList">
- <property name="text">
- <string>Clear</string>
- </property>
- </widget>
- </item>
- </layout>
+ <widget class="QLabel" name="label_7">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>History:</string>
+ </property>
+ </widget>
</item>
<item>
- <widget class="QListWidget" name="listWidgetResult">
- <property name="font">
- <font>
- <family>Monospace</family>
- </font>
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClearHistory">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
+ <item>
+ <widget class="QListWidget" name="listWidgetHistory"/>
+ </item>
</layout>
</widget>
- <widget class="QWidget" name="tabEdit">
+ <widget class="QWidget" name="tab">
<attribute name="title">
- <string>Result as edit field</string>
+ <string>Command pad</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_4">
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QPushButton" name="pushButton">
- <property name="minimumSize">
- <size>
- <width>125</width>
- <height>0</height>
- </size>
- </property>
+ <widget class="QLabel" name="label">
<property name="text">
- <string>From List</string>
+ <string>Write command, try "help;"</string>
</property>
</widget>
</item>
<item>
- <spacer name="horizontalSpacer_3">
+ <spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item>
- <widget class="QPushButton" name="pushButtonClearEdit">
+ <widget class="QPushButton" name="pushButtonRun">
<property name="minimumSize">
<size>
<width>125</width>
</size>
</property>
<property name="text">
- <string>Clear</string>
+ <string>Run</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonSave">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
- <widget class="QPlainTextEdit" name="plainTextEditResult">
- <property name="font">
- <font>
- <family>FreeMono</family>
- </font>
- </property>
- </widget>
+ <widget class="QPlainTextEdit" name="plainTextEditPad"/>
</item>
</layout>
</widget>
- <widget class="QWidget" name="tabBuffers">
+ <widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Buffers</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_8">
+ <layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
</item>
</layout>
</widget>
- <widget class="QWidget" name="layoutWidget">
+ <widget class="QWidget" name="layoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
</layout>
</widget>
</widget>
+ <widget class="QTabWidget" name="tabWidgetResult">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tabList">
+ <attribute name="title">
+ <string>Result as list</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_8">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Suche:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="comboBox">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonPrevious">
+ <property name="maximumSize">
+ <size>
+ <width>25</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string><</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton_2">
+ <property name="maximumSize">
+ <size>
+ <width>25</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClearList">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidgetResult">
+ <property name="font">
+ <font>
+ <family>Monospace</family>
+ </font>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabEdit">
+ <attribute name="title">
+ <string>Result as edit field</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>From List</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClearEdit">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="plainTextEditResult">
+ <property name="font">
+ <font>
+ <family>FreeMono</family>
+ </font>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
</widget>
</item>
</layout>