Repository: microsoft/terminal
File: src/buffer/out/TextColor.h (C/C++)

Code before:
Author(s):
- Mike Griese (migrie) Nov 2018

Revision History:
- From components of output.h/.c
  by Therese Stowell (ThereseS) 1990-1991
- Pulled into its own file from textBuffer.hpp/cpp (AustDi, 2017)
- Moved the colors into their own separate abstraction. (migrie Nov 2018)
--*/

#pragma once

#ifdef UNIT_TESTING
#include "WexTestClass.h"
#endif

// The enum values being in this particular order allows the compiler to do some useful optimizations,
// like simplifying `IsIndex16() || IsIndex256()` into a simple range check without branching.
enum class ColorType : BYTE
{
    IsDefault,
    IsIndex16,
    IsIndex256,
    IsIndex256Colon,
    IsRgb,
    IsRgbColon
};

enum class ColorAlias : size_t
{
    DefaultForeground,
    DefaultBackground,
    FrameForeground,
    FrameBackground,
    ENUM_COUNT // must be the last element in the enum class
};

struct TextColor
{
public:
    static constexpr BYTE DARK_BLACK = 0;
    static constexpr BYTE DARK_RED = 1;
    static constexpr BYTE DARK_GREEN = 2;
    static constexpr BYTE DARK_YELLOW = 3;
    static constexpr BYTE DARK_BLUE = 4;
    static constexpr BYTE DARK_MAGENTA = 5;
    static constexpr BYTE DARK_CYAN = 6;
    static constexpr BYTE DARK_WHITE = 7;
    static constexpr BYTE BRIGHT_BLACK = 8;
    static constexpr BYTE BRIGHT_RED = 9;
    static constexpr BYTE BRIGHT_GREEN = 10;

Review comment (suggestion):
@lhecker You mentioned something about the optimization above `ColorType` declaration. Does the addition of new options negatively affects it in any way 🤔

I assume if contiguous values are Or'd, it gets compiled as range check by the compiler, right? Then there shouldn't be any effect, since I added them after index256. I suppose the same optimization should also apply to modified `IsRgb()` and `IsIndex256()`, since they basically do the same thing.

Code after:
Author(s):
- Mike Griese (migrie) Nov 2018

Revision History:
- From components of output.h/.c
  by Therese Stowell (ThereseS) 1990-1991
- Pulled into its own file from textBuffer.hpp/cpp (AustDi, 2017)
- Moved the colors into their own separate abstraction. (migrie Nov 2018)
--*/

#pragma once

#ifdef UNIT_TESTING
#include "WexTestClass.h"
#endif

// The enum values being in this particular order allows the compiler to do some useful optimizations,
// like simplifying `IsIndex16() || IsIndex256()` into a simple range check without branching.
enum class ColorType : BYTE
{
    IsDefault,
    IsIndex16,
    IsIndex256,
    IsRgb
};

enum class ColorAlias : size_t
{
    DefaultForeground,
    DefaultBackground,
    FrameForeground,
    FrameBackground,
    ENUM_COUNT // must be the last element in the enum class
};

struct TextColor
{
public:
    static constexpr BYTE DARK_BLACK = 0;
    static constexpr BYTE DARK_RED = 1;
    static constexpr BYTE DARK_GREEN = 2;
    static constexpr BYTE DARK_YELLOW = 3;
    static constexpr BYTE DARK_BLUE = 4;
    static constexpr BYTE DARK_MAGENTA = 5;
    static constexpr BYTE DARK_CYAN = 6;
    static constexpr BYTE DARK_WHITE = 7;
    static constexpr BYTE BRIGHT_BLACK = 8;
    static constexpr BYTE BRIGHT_RED = 9;
    static constexpr BYTE BRIGHT_GREEN = 10;
    static constexpr BYTE BRIGHT_YELLOW = 11;
    static constexpr BYTE BRIGHT_BLUE = 12;