123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #pragma once
- #include "fwd.h"
- #include <util/generic/string.h>
- #include <util/generic/strbuf.h>
- #include <cstdio>
- namespace NColorizer {
-
- enum EAnsiCode: i8 {
-
-
- INVALID,
-
- RESET,
-
- ST_LIGHT,
- ST_DARK,
- ST_NORMAL,
-
- ITALIC_ON,
- ITALIC_OFF,
- UNDERLINE_ON,
- UNDERLINE_OFF,
-
- FG_DEFAULT,
- FG_BLACK,
- FG_RED,
- FG_GREEN,
- FG_YELLOW,
- FG_BLUE,
- FG_MAGENTA,
- FG_CYAN,
- FG_WHITE,
-
- BG_DEFAULT,
- BG_BLACK,
- BG_RED,
- BG_GREEN,
- BG_YELLOW,
- BG_BLUE,
- BG_MAGENTA,
- BG_CYAN,
- BG_WHITE,
-
- DEFAULT,
- BLACK,
- RED,
- GREEN,
- YELLOW,
- BLUE,
- MAGENTA,
- CYAN,
- WHITE,
- LIGHT_DEFAULT,
- LIGHT_BLACK,
- LIGHT_RED,
- LIGHT_GREEN,
- LIGHT_YELLOW,
- LIGHT_BLUE,
- LIGHT_MAGENTA,
- LIGHT_CYAN,
- LIGHT_WHITE,
- DARK_DEFAULT,
- DARK_BLACK,
- DARK_RED,
- DARK_GREEN,
- DARK_YELLOW,
- DARK_BLUE,
- DARK_MAGENTA,
- DARK_CYAN,
- DARK_WHITE,
- };
-
- class TColors {
- public:
- static bool CalcIsTTY(FILE* file);
- public:
- explicit TColors(FILE* = stderr);
- explicit TColors(bool ontty);
- TStringBuf Reset() const noexcept;
- TStringBuf StyleLight() const noexcept;
- TStringBuf StyleDark() const noexcept;
- TStringBuf StyleNormal() const noexcept;
- TStringBuf ItalicOn() const noexcept;
- TStringBuf ItalicOff() const noexcept;
- TStringBuf UnderlineOn() const noexcept;
- TStringBuf UnderlineOff() const noexcept;
- TStringBuf ForeDefault() const noexcept;
- TStringBuf ForeBlack() const noexcept;
- TStringBuf ForeRed() const noexcept;
- TStringBuf ForeGreen() const noexcept;
- TStringBuf ForeYellow() const noexcept;
- TStringBuf ForeBlue() const noexcept;
- TStringBuf ForeMagenta() const noexcept;
- TStringBuf ForeCyan() const noexcept;
- TStringBuf ForeWhite() const noexcept;
- TStringBuf BackDefault() const noexcept;
- TStringBuf BackBlack() const noexcept;
- TStringBuf BackRed() const noexcept;
- TStringBuf BackGreen() const noexcept;
- TStringBuf BackYellow() const noexcept;
- TStringBuf BackBlue() const noexcept;
- TStringBuf BackMagenta() const noexcept;
- TStringBuf BackCyan() const noexcept;
- TStringBuf BackWhite() const noexcept;
- TStringBuf Default() const noexcept;
- TStringBuf Black() const noexcept;
- TStringBuf Red() const noexcept;
- TStringBuf Green() const noexcept;
- TStringBuf Yellow() const noexcept;
- TStringBuf Blue() const noexcept;
- TStringBuf Magenta() const noexcept;
- TStringBuf Cyan() const noexcept;
- TStringBuf White() const noexcept;
- TStringBuf LightDefault() const noexcept;
- TStringBuf LightBlack() const noexcept;
- TStringBuf LightRed() const noexcept;
- TStringBuf LightGreen() const noexcept;
- TStringBuf LightYellow() const noexcept;
- TStringBuf LightBlue() const noexcept;
- TStringBuf LightMagenta() const noexcept;
- TStringBuf LightCyan() const noexcept;
- TStringBuf LightWhite() const noexcept;
- TStringBuf DarkDefault() const noexcept;
- TStringBuf DarkBlack() const noexcept;
- TStringBuf DarkRed() const noexcept;
- TStringBuf DarkGreen() const noexcept;
- TStringBuf DarkYellow() const noexcept;
- TStringBuf DarkBlue() const noexcept;
- TStringBuf DarkMagenta() const noexcept;
- TStringBuf DarkCyan() const noexcept;
- TStringBuf DarkWhite() const noexcept;
-
-
-
-
-
- TStringBuf OldColor() const noexcept;
- TStringBuf BoldColor() const noexcept;
- TStringBuf BlackColor() const noexcept;
- TStringBuf BlueColor() const noexcept;
- TStringBuf GreenColor() const noexcept;
- TStringBuf CyanColor() const noexcept;
- TStringBuf RedColor() const noexcept;
- TStringBuf PurpleColor() const noexcept;
- TStringBuf BrownColor() const noexcept;
- TStringBuf LightGrayColor() const noexcept;
- TStringBuf DarkGrayColor() const noexcept;
- TStringBuf LightBlueColor() const noexcept;
- TStringBuf LightGreenColor() const noexcept;
- TStringBuf LightCyanColor() const noexcept;
- TStringBuf LightRedColor() const noexcept;
- TStringBuf LightPurpleColor() const noexcept;
- TStringBuf YellowColor() const noexcept;
- TStringBuf WhiteColor() const noexcept;
- inline bool IsTTY() const noexcept {
- return IsTTY_;
- }
- inline void SetIsTTY(bool value) noexcept {
- IsTTY_ = value;
- }
- inline void Enable() noexcept {
- SetIsTTY(true);
- }
- inline void Disable() noexcept {
- SetIsTTY(false);
- }
- private:
- bool IsTTY_;
- };
-
- TColors& StdErr();
- TColors& StdOut();
-
-
- TColors& AutoColors(IOutputStream& os);
-
- size_t TotalAnsiEscapeCodeLen(TStringBuf text);
- }
- TStringBuf ToStringBuf(NColorizer::EAnsiCode x);
- TString ToString(NColorizer::EAnsiCode x);
|