Simple Qt5 text editor

The "io_editor" component is a simple Qt5 text editor that writes to
standard out and reads back from stdin. It is intended for use with an
interactive interpreter, such as a shell. The "terminal_editor" depot
package is provided to connect the editor to a terminal server.
This commit is contained in:
Emery Hemingway
2019-01-05 18:18:32 +01:00
committed by Norman Feske
parent fd713e737d
commit 6ca9087a23
14 changed files with 487 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
A simple text editor for reading and writing to a Terminal session
This editor is intended for interacting with a intepreter,
input and output is written in chunks, not byte-by-byte.

View File

@@ -0,0 +1,19 @@
genodelabs/raw/qt5_dejavusans/2018-09-06
genodelabs/src/expat/2018-11-26
genodelabs/src/freetype/2018-11-26
genodelabs/src/jpeg/2018-11-26
genodelabs/src/libc/2018-11-27
genodelabs/src/libpng/2018-11-26
genodelabs/src/mesa/2018-11-27
genodelabs/src/pcre16/2018-11-26
genodelabs/src/qt5_component/2018-11-27
genodelabs/src/qt5_core/2018-11-27
genodelabs/src/qt5_gui/2018-11-26
genodelabs/src/qt5_printsupport/2018-11-26
genodelabs/src/qt5_qjpeg/2018-11-26
genodelabs/src/qt5_qpa_nitpicker/2018-11-27
genodelabs/src/qt5_widgets/2018-11-26
genodelabs/src/stdcxx/2018-11-26
genodelabs/src/vfs/2018-11-27
genodelabs/src/zlib/2018-11-26
_/src/io_editor

View File

@@ -0,0 +1 @@
2019-01-05 b363069b287c6dae54c52fd9f12f01c3c0d8c345

View File

@@ -0,0 +1,52 @@
<runtime ram="16M" caps="256" binary="io_editor">
<requires>
<nitpicker/>
<timer/>
</requires>
<content>
<!-- common for Qt GUI applications -->
<rom label="egl.lib.so"/>
<rom label="expat.lib.so"/>
<rom label="freetype.lib.so"/>
<rom label="glapi.lib.so"/>
<rom label="jpeg.lib.so"/>
<rom label="libc.lib.so"/>
<rom label="libc_pipe.lib.so"/>
<rom label="libm.lib.so"/>
<rom label="libpng.lib.so"/>
<rom label="mesa.lib.so"/>
<rom label="pcre16.lib.so"/>
<rom label="qt5_core.lib.so"/>
<rom label="qt5_dejavusans.tar"/>
<rom label="qt5_gui.lib.so"/>
<rom label="qt5_qjpeg.lib.so"/>
<rom label="qt5_qpa_nitpicker.lib.so"/>
<rom label="stdcxx.lib.so"/>
<rom label="vfs.lib.so"/>
<rom label="zlib.lib.so"/>
<!-- application -->
<rom label="qt5_component.lib.so"/>
<rom label="qt5_printsupport.lib.so"/>
<rom label="qt5_widgets.lib.so"/>
<rom label="io_editor"/>
</content>
<config>
<vfs>
<dir name="dev">
<log/>
<terminal/>
</dir>
<tar name="qt5_dejavusans.tar"/>
</vfs>
<libc stdin="/dev/terminal" stdout="/dev/terminal" stderr="/dev/log"/>
</config>
</runtime>

View File

@@ -0,0 +1,15 @@
MIRROR_FROM_LIBPORTS = src/app/qt5/tmpl
MIRROR_FROM_REP_DIR := src/app/io_editor
content: $(MIRROR_FROM_LIBPORTS) $(MIRROR_FROM_REP_DIR) LICENSE
$(MIRROR_FROM_REP_DIR):
$(mirror_from_rep_dir)
$(MIRROR_FROM_LIBPORTS):
mkdir -p $(@)
cp $(GENODE_DIR)/repos/libports/$@/* $@
LICENSE:
cp $(GENODE_DIR)/LICENSE $@

View File

@@ -0,0 +1 @@
2019-01-04 70c1fea117ab4315889afb0d6821037187667496

View File

@@ -0,0 +1,11 @@
base
libc
mesa
qt5_component
qt5_core
qt5_gui
qt5_printsupport
qt5_qjpeg
qt5_qpa_nitpicker
qt5_widgets
stdcxx

View File

@@ -0,0 +1,155 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "highlighter.h"
//! [0]
Highlighter::Highlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
HighlightingRule rule;
keywordFormat.setForeground(Qt::darkBlue);
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns;
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
<< "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
<< "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
<< "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
<< "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
<< "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
<< "\\bvoid\\b" << "\\bvolatile\\b";
foreach (const QString &pattern, keywordPatterns) {
rule.pattern = QRegExp(pattern);
rule.format = keywordFormat;
highlightingRules.append(rule);
//! [0] //! [1]
}
//! [1]
//! [2]
classFormat.setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
rule.format = classFormat;
highlightingRules.append(rule);
//! [2]
//! [3]
singleLineCommentFormat.setForeground(Qt::red);
rule.pattern = QRegExp("//[^\n]*");
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::red);
//! [3]
//! [4]
quotationFormat.setForeground(Qt::darkGreen);
rule.pattern = QRegExp("\".*\"");
rule.format = quotationFormat;
highlightingRules.append(rule);
//! [4]
//! [5]
functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
rule.format = functionFormat;
highlightingRules.append(rule);
//! [5]
//! [6]
commentStartExpression = QRegExp("/\\*");
commentEndExpression = QRegExp("\\*/");
}
//! [6]
//! [7]
void Highlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
}
}
//! [7] //! [8]
setCurrentBlockState(0);
//! [8]
//! [9]
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = commentStartExpression.indexIn(text);
//! [9] //! [10]
while (startIndex >= 0) {
//! [10] //! [11]
int endIndex = commentEndExpression.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ commentEndExpression.matchedLength();
}
setFormat(startIndex, commentLength, multiLineCommentFormat);
startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
}
}
//! [11]

View File

@@ -0,0 +1,92 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
QT_BEGIN_NAMESPACE
class QTextDocument;
QT_END_NAMESPACE
//! [0]
class Highlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
Highlighter(QTextDocument *parent = 0);
protected:
void highlightBlock(const QString &text) override;
private:
struct HighlightingRule
{
QRegExp pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
QRegExp commentStartExpression;
QRegExp commentEndExpression;
QTextCharFormat keywordFormat;
QTextCharFormat classFormat;
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
QTextCharFormat functionFormat;
};
//! [0]
#endif // HIGHLIGHTER_H

View File

@@ -0,0 +1,13 @@
QT += widgets
HEADERS = \
highlighter.h \
mainwindow.h
SOURCES = \
highlighter.cpp \
mainwindow.cpp \
main.cpp
# install
#target.path = $$[QT_INSTALL_EXAMPLES]/widgets/richtext/syntaxhighlighter
INSTALLS += target

View File

@@ -0,0 +1,12 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.resize(640, 512);
window.show();
return app.exec();
}

View File

@@ -0,0 +1,62 @@
#include <QtWidgets>
#include <QHBoxLayout>
#include "mainwindow.h"
/* Libc includes */
#include <unistd.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
remote_editor = new QTextEdit;
local_editor = new QTextEdit;
setupEditor(remote_editor);
setupEditor(local_editor);
remote_editor->setReadOnly(true);
QPushButton *button = new QPushButton("Submit", this);
connect(button, &QAbstractButton::clicked, this, &MainWindow::submit);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(remote_editor);
layout->addWidget(local_editor);
layout->addWidget(button);
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Enter), this, SLOT(submit()));
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this, SLOT(submit()));
}
void MainWindow::setupEditor(QTextEdit *editor)
{
QFont font;
font.setFamily("Courier");
font.setFixedPitch(true);
font.setPointSize(10);
editor->setFont(font);
//highlighter = new Highlighter(editor->document());
}
void MainWindow::load()
{
char buf[4096];
ssize_t n = read(0, buf, sizeof(buf)-1);
buf[n] = 0;
remote_editor->setPlainText(QString(buf));
}
void MainWindow::submit()
{
QByteArray b = local_editor->toPlainText().toLocal8Bit();
if (b.size() > 0)
write(1, b.data(), b.size());
load();
}

View File

@@ -0,0 +1,33 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "highlighter.h"
#include <QMainWindow>
#include <QTextStream>
QT_BEGIN_NAMESPACE
class QTextEdit;
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void submit();
private:
void setupEditor(QTextEdit *editor);
void load();
QTextEdit *remote_editor;
QTextEdit *local_editor;
//Highlighter *highlighter;
};
#endif // MAINWINDOW_H

View File

@@ -0,0 +1,15 @@
QT5_PORT_DIR := $(call select_from_ports,qt5)
QT5_CONTRIB_DIR := $(QT5_PORT_DIR)/src/lib/qt5/qt5
QMAKE_PROJECT_PATH = $(REP_DIR)/src/app/io_editor
QMAKE_PROJECT_FILE = $(QMAKE_PROJECT_PATH)/io_editor.pro
vpath % $(QMAKE_PROJECT_PATH)
include $(call select_from_repositories,src/app/qt5/tmpl/target_defaults.inc)
include $(call select_from_repositories,src/app/qt5/tmpl/target_final.inc)
LIBS += qt5_component qt5_printsupport
CC_CXX_WARN_STRICT =