2014-10-17 09:45:46 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-10-18 09:27:04 +02:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
|
2014-10-17 09:45:46 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONSOLE_H
|
|
|
|
#define CONSOLE_H
|
|
|
|
|
|
|
|
#include "base/i2-base.hpp"
|
2018-01-04 18:24:45 +01:00
|
|
|
#include <iosfwd>
|
2014-10-17 09:45:46 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
enum ConsoleColor
|
|
|
|
{
|
|
|
|
Console_Normal,
|
|
|
|
|
|
|
|
// bit 0-7: foreground
|
|
|
|
Console_ForegroundBlack = 1,
|
|
|
|
Console_ForegroundRed = 2,
|
|
|
|
Console_ForegroundGreen = 3,
|
|
|
|
Console_ForegroundYellow = 4,
|
|
|
|
Console_ForegroundBlue = 5,
|
|
|
|
Console_ForegroundMagenta = 6,
|
|
|
|
Console_ForegroundCyan = 7,
|
|
|
|
Console_ForegroundWhite = 8,
|
|
|
|
|
|
|
|
// bit 8-15: background
|
|
|
|
Console_BackgroundBlack = 256,
|
|
|
|
Console_BackgroundRed = 266,
|
|
|
|
Console_BackgroundGreen = 267,
|
|
|
|
Console_BackgroundYellow = 268,
|
|
|
|
Console_BackgroundBlue = 269,
|
|
|
|
Console_BackgroundMagenta = 270,
|
|
|
|
Console_BackgroundCyan = 271,
|
|
|
|
Console_BackgroundWhite = 272,
|
|
|
|
|
|
|
|
// bit 16-23: flags
|
|
|
|
Console_Bold = 65536
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ConsoleType
|
|
|
|
{
|
2015-03-17 10:42:46 +01:00
|
|
|
Console_Autodetect = -1,
|
|
|
|
|
2014-10-17 09:45:46 +02:00
|
|
|
Console_Dumb,
|
|
|
|
#ifndef _WIN32
|
|
|
|
Console_VT100,
|
|
|
|
#else /* _WIN32 */
|
|
|
|
Console_Windows,
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
};
|
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
class ConsoleColorTag
|
2014-10-17 09:45:46 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-03-17 10:42:46 +01:00
|
|
|
ConsoleColorTag(int color, ConsoleType consoleType = Console_Autodetect);
|
2014-10-17 09:45:46 +02:00
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
friend std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
|
2014-10-17 09:45:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_Color;
|
2014-12-16 12:22:02 +01:00
|
|
|
int m_ConsoleType;
|
2014-10-17 09:45:46 +02:00
|
|
|
};
|
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
|
2014-11-08 21:17:16 +01:00
|
|
|
|
2014-10-17 09:45:46 +02:00
|
|
|
/**
|
|
|
|
* Console utilities.
|
|
|
|
*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class Console
|
2014-10-17 09:45:46 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-01-04 04:25:35 +01:00
|
|
|
static void DetectType();
|
2014-10-17 09:45:46 +02:00
|
|
|
|
|
|
|
static void SetType(std::ostream& fp, ConsoleType type);
|
|
|
|
static ConsoleType GetType(std::ostream& fp);
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
static void PrintVT100ColorCode(std::ostream& fp, int color);
|
|
|
|
#else /* _WIN32 */
|
|
|
|
static void SetWindowsConsoleColor(std::ostream& fp, int color);
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
private:
|
2018-01-04 04:25:35 +01:00
|
|
|
Console();
|
2014-10-17 09:45:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONSOLE_H */
|