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