1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QCOLOROUTPUT_H |
5 | #define QCOLOROUTPUT_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | |
17 | #include <private/qtqmlcompilerexports_p.h> |
18 | |
19 | #include <QtCore/private/qglobal_p.h> |
20 | #include <QtCore/qscopedpointer.h> |
21 | #include <QtCore/qstring.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QColorOutputPrivate; |
26 | |
27 | class Q_QMLCOMPILER_PRIVATE_EXPORT QColorOutput |
28 | { |
29 | enum |
30 | { |
31 | ForegroundShift = 10, |
32 | BackgroundShift = 20, |
33 | SpecialShift = 20, |
34 | ForegroundMask = 0x1f << ForegroundShift, |
35 | BackgroundMask = 0x7 << BackgroundShift |
36 | }; |
37 | |
38 | public: |
39 | enum ColorCodeComponent |
40 | { |
41 | BlackForeground = 1 << ForegroundShift, |
42 | BlueForeground = 2 << ForegroundShift, |
43 | GreenForeground = 3 << ForegroundShift, |
44 | CyanForeground = 4 << ForegroundShift, |
45 | RedForeground = 5 << ForegroundShift, |
46 | PurpleForeground = 6 << ForegroundShift, |
47 | BrownForeground = 7 << ForegroundShift, |
48 | LightGrayForeground = 8 << ForegroundShift, |
49 | DarkGrayForeground = 9 << ForegroundShift, |
50 | LightBlueForeground = 10 << ForegroundShift, |
51 | LightGreenForeground = 11 << ForegroundShift, |
52 | LightCyanForeground = 12 << ForegroundShift, |
53 | LightRedForeground = 13 << ForegroundShift, |
54 | LightPurpleForeground = 14 << ForegroundShift, |
55 | YellowForeground = 15 << ForegroundShift, |
56 | WhiteForeground = 16 << ForegroundShift, |
57 | |
58 | BlackBackground = 1 << BackgroundShift, |
59 | BlueBackground = 2 << BackgroundShift, |
60 | GreenBackground = 3 << BackgroundShift, |
61 | CyanBackground = 4 << BackgroundShift, |
62 | RedBackground = 5 << BackgroundShift, |
63 | PurpleBackground = 6 << BackgroundShift, |
64 | BrownBackground = 7 << BackgroundShift, |
65 | DefaultColor = 1 << SpecialShift |
66 | }; |
67 | |
68 | using ColorCode = QFlags<ColorCodeComponent>; |
69 | using ColorMapping = QHash<int, ColorCode>; |
70 | |
71 | QColorOutput(); |
72 | ~QColorOutput(); |
73 | |
74 | bool isSilent() const; |
75 | void setSilent(bool silent); |
76 | |
77 | void insertMapping(int colorID, ColorCode colorCode); |
78 | |
79 | void writeUncolored(const QString &message); |
80 | void write(const QStringView message, int color = -1); |
81 | // handle QStringBuilder case |
82 | Q_WEAK_OVERLOAD void write(const QString &message, int color = -1) { write(message: QStringView(message), color); } |
83 | void writePrefixedMessage(const QString &message, QtMsgType type, |
84 | const QString &prefix = QString()); |
85 | QString colorify(QStringView message, int color = -1) const; |
86 | |
87 | private: |
88 | QScopedPointer<QColorOutputPrivate> d; |
89 | Q_DISABLE_COPY_MOVE(QColorOutput) |
90 | }; |
91 | |
92 | Q_DECLARE_OPERATORS_FOR_FLAGS(QColorOutput::ColorCode) |
93 | |
94 | QT_END_NAMESPACE |
95 | |
96 | #endif // QCOLOROUTPUT_H |
97 | |