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

47
tests/t-color16M.cpp Normal file
View file

@ -0,0 +1,47 @@
#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(120,255,120); // greenish
clutchlog::fmt warning("#ff0055", typo::bold); // magentaish
clutchlog::fmt error(255,100,150, typo::bold); // redish magenta
clutchlog::fmt critical("#ffff00", "#ff0000"); // 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("#888888", typo::inverse);
format << "{level}: "
<< discreet("{file}") << ":"
<< clutchlog::fmt(/*front RGB*/200,150,0, /*back RGB*/0,0,0) << "{line}" // gold yellow over black
<< clutchlog::fmt(typo::reset) << " {msg} ! " << std::endl;
log.format(format.str());
CLUTCHLOG(critical,"After having inserted styles within a new format template");
}

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");
}

View file

@ -0,0 +1,45 @@
#include <iostream>
#include <limits>
#include "../clutchlog/clutchlog.h"
int main(/*const int argc, char* argv[]*/)
{
using fmt = clutchlog::fmt;
using fg = clutchlog::fmt::fg;
using bg = clutchlog::fmt::bg;
using typo = clutchlog::fmt::typo;
fmt none;
fmt c16_full(fg::red , bg::black , typo::bold);
fmt c16_nofg(bg::black , typo::bold);
fmt c16_nobg(fg::red , typo::bold);
fmt c16_fg (fg::red );
fmt c16_bg (bg::red );
fmt c16_typo(typo::bold);
fmt c16_bft (bg::black , fg::red , typo::bold);
fmt c16_bgfg(bg::black , fg::red );
fmt c16_tbf (typo::bold, bg::black , fg::red );
fmt c16_tfb (typo::bold, fg::red , bg::black );
fmt c16_tf (typo::bold, fg::red );
fmt c16_tb (typo::bold, bg::black );
fmt c256_fbt(196 , 236 , typo::bold);
fmt c256_ft (196 , typo::bold);
fmt c256_fb (196 , 236 );
fmt c256_nbt(fg::none, 236 , typo::bold);
fmt c256_fnt(196 , bg::none , typo::bold);
fmt c256_nb (fg::none, 236 );
fmt c256_fn (196 , bg::none );
fmt c16M_fbt(255,10,10 , 10,10,20 , typo::bold);
fmt c16M_ft (255,10,10 , typo::bold);
fmt c16M_fb (255,10,10 , 10,10,20 );
fmt c16M_nbt(fg::none , 10,10,20 , typo::bold);
fmt c16M_fnt(255,10,10 , bg::none , typo::bold);
fmt c16M_nb (fg::none , 10,10,20 );
fmt c16M_fn (255,10,10 , bg::none );
}

14
tests/t-one-line-if.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "../clutchlog/clutchlog.h"
int main()
{
if(true)
CLUTCHLOG(error, "WHAT?");
else
CLUTCHLOG(info, "OH!");
if(false)
CLUTCHLOG(info, "AH!");
else
CLUTCHLOG(error, "NO!");
}