feat(colors): adds 256 and 16M colors mode support in fmt

This commit is contained in:
Johann Dreo 2023-01-23 12:08:09 +01:00
commit 7955ec197f
6 changed files with 795 additions and 75 deletions

46
tests/t-color256.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <iostream>
#include <limits>
#include "../clutchlog/clutchlog.h"
int main(/*const int argc, char* argv[]*/)
{
using typo = clutchlog::fmt::typo;
// using fg = clutchlog::fmt::fg;
// using bg = clutchlog::fmt::bg;
clutchlog::fmt none;
clutchlog::fmt end(typo::reset);
clutchlog::fmt note(typo::bold);
clutchlog::fmt info(106); // greenish
clutchlog::fmt warning(171, typo::bold); // magentaish
clutchlog::fmt error(198, typo::bold); // redish magenta
clutchlog::fmt critical(226, 196, typo::underline); // Yellow over red.
auto& log = clutchlog::logger();
log.threshold(clutchlog::level::info);
// Change a style.
log.style(clutchlog::level::critical, error);
CLUTCHLOG(critical,"Styles demo");
CLUTCHLOG(info,"Either using functions...");
std::cout << none("No style: ") << std::endl;
std::cout << note("NOTE: bold") << std::endl;
std::cout << info("INFO: green") << std::endl;
CLUTCHLOG(info,"... or tags.");
std::cout << warning << "WARNING" << end << ": bold magenta" << std::endl;
std::cout << error << "ERROR" << end << ": bold red" << std::endl;
std::cout << critical << "CRITICAL" << end << ": underlined black over red background" << std::endl;
std::ostringstream format;
clutchlog::fmt discreet(254);
format << "{level}: "
<< discreet("{file}:")
<< clutchlog::fmt(220, typo::inverse) << "{line}" // gold yellow
<< clutchlog::fmt(typo::reset) << " {msg} ! " << std::endl;
log.format(format.str());
CLUTCHLOG(critical,"After having inserted styles within a new format template");
}