Lunar-Eclipse255 / maelstrom

SD Card logging library for PROS
https://lunar-eclipse255.github.io/maelstrom/
MIT License
2 stars 0 forks source link

Add colored messages using rtf #13

Open Lunar-Eclipse255 opened 1 month ago

Voidless7125 commented 1 month ago

Colored messages should also have the corresponding level to them, or a custom color of user choice? Ex in green: [Trace] test1 ex in red: [Error] very bad error

Voidless7125 commented 1 month ago

Here are some color codes (from my comp v5 program, but this will only work on a terminal)

/// @brief *For loghandler*
/// @param str takes Log::Level level
/// @return Color code of Log::Level in string.
const char *LogToColor(const Log::Level &str)
{
    switch (str)
    {
    case Log::Level::Trace:
    {
        return "\033[92m[Trace]";
    }

    case Log::Level::Debug:
    {
        return "\033[93m[Debug]";
    }

    case Log::Level::Info:
    {
        return "\033[94m[Info]";
    }

    case Log::Level::Warn:
    {
        return " \033[38;5;216m[Warn]";
    }

    case Log::Level::Error:
    {
        return "\033[31m[Error]";
    }

    case Log::Level::Fatal:
    {
        return "\033[32m[Fatal]";
    }
    default:
    {
        return "\033[31m[Error]";
    }
    }
}
Voidless7125 commented 1 month ago

Some RTF c++ libraries info: https://librtf.sourceforge.net/ https://cplusplus.com/doc/tutorial/files/ https://www.leadtools.com/help/sdk/v22/main/clib/rich-text-format-rtf.html

Lunar-Eclipse255 commented 1 month ago

Just created a new branch called rtf_color_messages, to work on this to not disturb the main branch, and when the switch to rtf is done it can be merged

Voidless7125 commented 1 month ago

Some boiler?

 std::ofstream LogFile("log.rtf", std::ios_base::out | std::ios_base::app);
    if (confighere_withertoaddtofile)
    {
        if (!LogFile)
        {
            logHandler("logHandler", "Could not create logfile.", Log::Level::Warn, 3);
            ConfigManager.setLogToFile(false);
        }
        LogFile << "[" << LogToString(level) << "] > Time: " << Brain.Timer.time(vex::timeUnits::sec) << " > Module: " << functionName << " > " << message << "\n";
    }

More info https://www.biblioscape.com/rtf15_spec.htm

Voidless7125 commented 1 month ago

Is this working in the new branch?

Lunar-Eclipse255 commented 1 month ago

Yes but nothing is formatted properly yet, but the coloring does work. I've just been quite busy these past weeks

Voidless7125 commented 1 month ago

All good! Just a checkup :)