1/*
2 SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
8#define KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
9
10#include "abstracthighlighter.h"
11#include "ksyntaxhighlighting_export.h"
12
13#include <QFlags>
14#include <QString>
15
16QT_BEGIN_NAMESPACE
17class QIODevice;
18QT_END_NAMESPACE
19
20namespace KSyntaxHighlighting
21{
22class AnsiHighlighterPrivate;
23
24// Exported for a bundled helper program
25class KSYNTAXHIGHLIGHTING_EXPORT AnsiHighlighter final : public AbstractHighlighter
26{
27public:
28 enum class AnsiFormat {
29 TrueColor,
30 XTerm256Color,
31 };
32
33 enum class Option {
34 NoOptions,
35 UseEditorBackground = 1 << 0,
36 Unbuffered = 1 << 1,
37
38 // Options that displays a useful visual aid for syntax creation
39 TraceFormat = 1 << 2,
40 TraceRegion = 1 << 3,
41 TraceContext = 1 << 4,
42 TraceStackSize = 1 << 5,
43 TraceAll = TraceFormat | TraceRegion | TraceContext | TraceStackSize,
44 };
45 Q_DECLARE_FLAGS(Options, Option)
46
47 AnsiHighlighter();
48 ~AnsiHighlighter() override;
49
50 void highlightFile(const QString &fileName, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);
51 void highlightData(QIODevice *device, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);
52
53 void setOutputFile(const QString &fileName);
54 void setOutputFile(FILE *fileHandle);
55
56protected:
57 void applyFormat(int offset, int length, const Format &format) override;
58
59private:
60 Q_DECLARE_PRIVATE(AnsiHighlighter)
61};
62}
63
64Q_DECLARE_OPERATORS_FOR_FLAGS(KSyntaxHighlighting::AnsiHighlighter::Options)
65
66#endif // KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
67

source code of syntax-highlighting/src/lib/ansihighlighter.h