aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/syntax-highlighting/src/lib/ansihighlighter.h
blob: 0942aa0242b49d1f64030d1fd29e963784b240d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
    SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com>

    SPDX-License-Identifier: MIT
*/

#ifndef KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
#define KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H

#include "abstracthighlighter.h"
#include "ksyntaxhighlighting_export.h"

#include <QFlags>
#include <QString>

QT_BEGIN_NAMESPACE
class QIODevice;
QT_END_NAMESPACE

namespace KSyntaxHighlighting
{
class AnsiHighlighterPrivate;

// Exported for a bundled helper program
class KSYNTAXHIGHLIGHTING_EXPORT AnsiHighlighter final : public AbstractHighlighter
{
public:
    enum class AnsiFormat {
        TrueColor,
        XTerm256Color,
    };

    enum class Option {
        NoOptions,
        UseEditorBackground = 1 << 0,
        Unbuffered = 1 << 1,

        // Options that displays a useful visual aid for syntax creation
        TraceFormat = 1 << 2,
        TraceRegion = 1 << 3,
        TraceContext = 1 << 4,
        TraceStackSize = 1 << 5,
        TraceAll = TraceFormat | TraceRegion | TraceContext | TraceStackSize,
    };
    Q_DECLARE_FLAGS(Options, Option)

    AnsiHighlighter();
    ~AnsiHighlighter() override;

    void highlightFile(const QString &fileName, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);
    void highlightData(QIODevice *device, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);

    void setOutputFile(const QString &fileName);
    void setOutputFile(FILE *fileHandle);

protected:
    void applyFormat(int offset, int length, const Format &format) override;

private:
    Q_DECLARE_PRIVATE(AnsiHighlighter)
};
}

Q_DECLARE_OPERATORS_FOR_FLAGS(KSyntaxHighlighting::AnsiHighlighter::Options)

#endif // KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H