| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2019 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the tools applications of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #ifndef QCOLOROUTPUT_H | 
| 30 | #define QCOLOROUTPUT_H | 
| 31 |  | 
| 32 | // | 
| 33 | //  W A R N I N G | 
| 34 | //  ------------- | 
| 35 | // | 
| 36 | // This file is not part of the Qt API.  It exists purely as an | 
| 37 | // implementation detail.  This header file may change from version to | 
| 38 | // version without notice, or even be removed. | 
| 39 | // | 
| 40 | // We mean it. | 
| 41 |  | 
| 42 | #include <QtCore/qglobal.h> | 
| 43 | #include <QtCore/qscopedpointer.h> | 
| 44 |  | 
| 45 | class ColorOutputPrivate; | 
| 46 |  | 
| 47 | class ColorOutput | 
| 48 | { | 
| 49 |     enum | 
| 50 |     { | 
| 51 |         ForegroundShift = 10, | 
| 52 |         BackgroundShift = 20, | 
| 53 |         SpecialShift    = 20, | 
| 54 |         ForegroundMask  = 0x1f << ForegroundShift, | 
| 55 |         BackgroundMask  = 0x7 << BackgroundShift | 
| 56 |     }; | 
| 57 |  | 
| 58 | public: | 
| 59 |     enum ColorCodeComponent | 
| 60 |     { | 
| 61 |         BlackForeground         = 1 << ForegroundShift, | 
| 62 |         BlueForeground          = 2 << ForegroundShift, | 
| 63 |         GreenForeground         = 3 << ForegroundShift, | 
| 64 |         CyanForeground          = 4 << ForegroundShift, | 
| 65 |         RedForeground           = 5 << ForegroundShift, | 
| 66 |         PurpleForeground        = 6 << ForegroundShift, | 
| 67 |         BrownForeground         = 7 << ForegroundShift, | 
| 68 |         LightGrayForeground     = 8 << ForegroundShift, | 
| 69 |         DarkGrayForeground      = 9 << ForegroundShift, | 
| 70 |         LightBlueForeground     = 10 << ForegroundShift, | 
| 71 |         LightGreenForeground    = 11 << ForegroundShift, | 
| 72 |         LightCyanForeground     = 12 << ForegroundShift, | 
| 73 |         LightRedForeground      = 13 << ForegroundShift, | 
| 74 |         LightPurpleForeground   = 14 << ForegroundShift, | 
| 75 |         YellowForeground        = 15 << ForegroundShift, | 
| 76 |         WhiteForeground         = 16 << ForegroundShift, | 
| 77 |  | 
| 78 |         BlackBackground         = 1 << BackgroundShift, | 
| 79 |         BlueBackground          = 2 << BackgroundShift, | 
| 80 |         GreenBackground         = 3 << BackgroundShift, | 
| 81 |         CyanBackground          = 4 << BackgroundShift, | 
| 82 |         RedBackground           = 5 << BackgroundShift, | 
| 83 |         PurpleBackground        = 6 << BackgroundShift, | 
| 84 |         BrownBackground         = 7 << BackgroundShift, | 
| 85 |         DefaultColor            = 1 << SpecialShift | 
| 86 |     }; | 
| 87 |  | 
| 88 |     using ColorCode = QFlags<ColorCodeComponent>; | 
| 89 |     using ColorMapping = QHash<int, ColorCode>; | 
| 90 |  | 
| 91 |     ColorOutput(bool silent); | 
| 92 |     ~ColorOutput(); | 
| 93 |  | 
| 94 |     void insertMapping(int colorID, ColorCode colorCode); | 
| 95 |  | 
| 96 |     void writeUncolored(const QString &message); | 
| 97 |     void write(const QString &message, int color = -1); | 
| 98 |     QString colorify(const QString &message, int color = -1) const; | 
| 99 |  | 
| 100 | private: | 
| 101 |     QScopedPointer<ColorOutputPrivate> d; | 
| 102 |     Q_DISABLE_COPY_MOVE(ColorOutput) | 
| 103 | }; | 
| 104 |  | 
| 105 | Q_DECLARE_OPERATORS_FOR_FLAGS(ColorOutput::ColorCode) | 
| 106 |  | 
| 107 | #endif // QCOLOROUTPUT_H | 
| 108 |  |