2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-10-17 09:45:46 +02:00
|
|
|
|
|
|
|
#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 */
|