File indexing completed on 2024-05-12 15:50:03

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 <QIODevice>
0015 #include <QString>
0016 
0017 #include <memory>
0018 
0019 namespace KSyntaxHighlighting
0020 {
0021 class AnsiHighlighterPrivate;
0022 
0023 // Exported for a bundled helper program
0024 class KSYNTAXHIGHLIGHTING_EXPORT AnsiHighlighter final : public AbstractHighlighter
0025 {
0026 public:
0027     enum class AnsiFormat {
0028         TrueColor,
0029         XTerm256Color,
0030     };
0031 
0032     enum class TraceOption {
0033         NoOptions,
0034         Format = 1 << 0,
0035         Region = 1 << 1,
0036         Context = 1 << 2,
0037         StackSize = 1 << 3,
0038     };
0039     Q_DECLARE_FLAGS(TraceOptions, TraceOption)
0040 
0041     AnsiHighlighter();
0042     ~AnsiHighlighter() override;
0043 
0044     void highlightFile(const QString &fileName,
0045                        AnsiFormat format = AnsiFormat::TrueColor,
0046                        bool useEditorBackground = true,
0047                        TraceOptions traceOptions = TraceOptions());
0048     void
0049     highlightData(QIODevice *device, AnsiFormat format = AnsiFormat::TrueColor, bool useEditorBackground = true, TraceOptions traceOptions = TraceOptions());
0050 
0051     void setOutputFile(const QString &fileName);
0052     void setOutputFile(FILE *fileHandle);
0053 
0054 protected:
0055     void applyFormat(int offset, int length, const Format &format) override;
0056 
0057 private:
0058     std::unique_ptr<AnsiHighlighterPrivate> d;
0059 };
0060 }
0061 
0062 Q_DECLARE_OPERATORS_FOR_FLAGS(KSyntaxHighlighting::AnsiHighlighter::TraceOptions)
0063 
0064 #endif // KSYNTAXHIGHLIGHTING_ANSIHIGHLIGHTER_H