File indexing completed on 2024-05-12 04:02:17

0001 /*
0002     SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
0008 #define KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H
0009 
0010 #include "abstracthighlighter.h"
0011 #include "ksyntaxhighlighting_export.h"
0012 
0013 #include <QFlags>
0014 #include <QString>
0015 
0016 QT_BEGIN_NAMESPACE
0017 class QIODevice;
0018 QT_END_NAMESPACE
0019 
0020 namespace KSyntaxHighlighting
0021 {
0022 class AnsiHighlighterPrivate;
0023 
0024 // Exported for a bundled helper program
0025 class KSYNTAXHIGHLIGHTING_EXPORT AnsiHighlighter final : public AbstractHighlighter
0026 {
0027 public:
0028     enum class AnsiFormat {
0029         TrueColor,
0030         XTerm256Color,
0031     };
0032 
0033     enum class Option {
0034         NoOptions,
0035         UseEditorBackground = 1 << 0,
0036         Unbuffered = 1 << 1,
0037 
0038         // Options that displays a useful visual aid for syntax creation
0039         TraceFormat = 1 << 2,
0040         TraceRegion = 1 << 3,
0041         TraceContext = 1 << 4,
0042         TraceStackSize = 1 << 5,
0043         TraceAll = TraceFormat | TraceRegion | TraceContext | TraceStackSize,
0044     };
0045     Q_DECLARE_FLAGS(Options, Option)
0046 
0047     AnsiHighlighter();
0048     ~AnsiHighlighter() override;
0049 
0050     void highlightFile(const QString &fileName, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);
0051     void highlightData(QIODevice *device, AnsiFormat format = AnsiFormat::TrueColor, Options options = Option::UseEditorBackground);
0052 
0053     void setOutputFile(const QString &fileName);
0054     void setOutputFile(FILE *fileHandle);
0055 
0056 protected:
0057     void applyFormat(int offset, int length, const Format &format) override;
0058 
0059 private:
0060     Q_DECLARE_PRIVATE(AnsiHighlighter)
0061 };
0062 }
0063 
0064 Q_DECLARE_OPERATORS_FOR_FLAGS(KSyntaxHighlighting::AnsiHighlighter::Options)
0065 
0066 #endif // KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H