simple syntax highlighting
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
;; echo $(webrunner -h | sed -n 's, COMMAND: ,,p') | sed 's, ,\\\\|,g'
|
;; echo $(webrunner -h | sed -n 's, COMMAND: ,,p') | sed 's, ,\\\\|,g'
|
||||||
(defconst wt-font-lock-keywords
|
(defconst wt-font-lock-keywords
|
||||||
(list
|
(list
|
||||||
'("^ *\\(ca-certificate\\|call\\|case\\|check\\|clear-cookies\\|click\\|clicktype\\|client-certificate\\|do\\|download\\|echo\\|execute\\|exists\\|exit\\|expect\\|fail\\|for\\|function\\|if\\|ignoreto\\|include\\|label\\|load\\|not\\|offline-storage-path\\|open\\|screenshot\\|set\\|setvalue\\|sleep\\|testcase\\|testsuite\\|timeout\\|unset\\|upload\\) " . font-lock-builtin-face)
|
'("^ *\\(auth\\|ca-certificate\\|call\\|case\\|check\\|clear-cookies\\|click\\|clicktype\\|client-certificate\\|do\\|download\\|echo\\|execute\\|exists\\|exit\\|expect\\|fail\\|for\\|function\\|if\\|ignoreto\\|include\\|label\\|load\\|not\\|offline-storage-path\\|open\\|screenshot\\|set\\|setvalue\\|sleep\\|testcase\\|testsuite\\|timeout\\|unset\\|upload\\) " . font-lock-builtin-face)
|
||||||
'("^ *#.*$" . font-lock-comment-face))
|
'("^ *#.*$" . font-lock-comment-face))
|
||||||
"Highlighting expressions for Webtester")
|
"Highlighting expressions for Webtester")
|
||||||
|
|
||||||
|
@@ -6,6 +6,38 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
#include <QSyntaxHighlighter>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
|
|
||||||
|
class Highlighter: public QSyntaxHighlighter {
|
||||||
|
Q_OBJECT;
|
||||||
|
public:
|
||||||
|
Highlighter(QTextDocument *parent): QSyntaxHighlighter(parent) {
|
||||||
|
QString commands="auth|ca-certificate|call|case|check|clear-cookies|click|clicktype|client-certificate|do|download|echo|execute|exists|exit|expect|fail|for|function|if|ignoreto|include|label|load|not|offline-storage-path|open|screenshot|set|setvalue|sleep|testcase|testsuite|timeout|unset|upload";
|
||||||
|
_expressions<<Expression("^ *("+commands+")\\b").weight(QFont::Bold).fg(Qt::darkBlue)
|
||||||
|
<<Expression("^ *#.*$").weight(QFont::Bold).fg(Qt::black);
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
void highlightBlock(const QString &text) {
|
||||||
|
for (auto e: _expressions) {
|
||||||
|
auto m(e.re.match(text));
|
||||||
|
for (int i(0); i<=m.lastCapturedIndex(); ++i) {
|
||||||
|
setFormat(m.capturedStart(i), m.capturedLength(i), e.fmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
struct Expression {
|
||||||
|
Expression(QString s): re(s) {}
|
||||||
|
Expression(QString s, QTextCharFormat f): re(s), fmt(f) {}
|
||||||
|
Expression& weight(int w) {fmt.setFontWeight(w); return *this;}
|
||||||
|
Expression& fg(const QBrush& b) {fmt.setForeground(b); return *this;}
|
||||||
|
QRegularExpression re;
|
||||||
|
QTextCharFormat fmt;
|
||||||
|
};
|
||||||
|
QList<Expression> _expressions;
|
||||||
|
};
|
||||||
|
|
||||||
class CodeEditor;
|
class CodeEditor;
|
||||||
|
|
||||||
@@ -23,6 +55,7 @@ class CodeEditor: public QPlainTextEdit {
|
|||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
public:
|
public:
|
||||||
CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) {
|
CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) {
|
||||||
|
new Highlighter(document());
|
||||||
lineNumberArea = new LineNumberArea(this);
|
lineNumberArea = new LineNumberArea(this);
|
||||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||||
|
Reference in New Issue
Block a user