// Implementation of ConsoleColor for Unix (assume anything other than Windows).
#ifndef _WIN32

#include <unistd.h>

#include <Utilities/Utilities.hpp>
#include <Utilities/ConsoleColor.hpp>

static const char* getEscapeSequence(ConsoleColor color)
{
    switch (color)
    {
    case ConsoleColor::Black: return "\u001b[30m";
    case ConsoleColor::Red: return "\u001b[31m";
    case ConsoleColor::Green: return "\u001b[32m";
    case ConsoleColor::Yellow: return "\u001b[33m";
    case ConsoleColor::Blue: return "\u001b[34m";
    case ConsoleColor::Magenta: return "\u001b[35m";
    case ConsoleColor::Cyan: return "\u001b[36m";
    case ConsoleColor::White: return "\u001b[37m";
    case ConsoleColor::Reset: return "\u001b[0m";
    default: crash("Invalid console color!");
    }
}

std::ostream& operator<<(std::ostream &os, ConsoleColor color)
{
    if (!isatty(1))
    {
        // If cout is not a terminal, don't do anything.
        return os;
    }

    os << getEscapeSequence(color);
    return os;
}

#endif  /* _WIN32 */