Even better code than yesterday!
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Mutil::Console::General {
|
||||
namespace Mutil::Console::Graphics {
|
||||
// Text styling
|
||||
enum TextStyle : uint8_t {
|
||||
Reset = 0,
|
||||
Normal = 0,
|
||||
Bold,
|
||||
Dim,
|
||||
Italic,
|
||||
@@ -43,9 +43,7 @@ namespace Mutil::Console::Graphics {
|
||||
ResetInverse = 27,
|
||||
ResetHidden,
|
||||
ResetStrikethrough,
|
||||
|
||||
DefaultForegroundColor = 39,
|
||||
|
||||
DefaultBackgroundColor = 49,
|
||||
};
|
||||
|
||||
@@ -76,6 +74,128 @@ namespace Mutil::Console::Graphics {
|
||||
SetBackgroundColor = 48,
|
||||
};
|
||||
|
||||
const uint64_t RNormal = 0;
|
||||
const uint64_t RBold = 1<<0;
|
||||
const uint64_t RDim = 1<<1;
|
||||
const uint64_t RItalic = 1<<2;
|
||||
const uint64_t RUnderline = 1<<3;
|
||||
const uint64_t RBlink = 1<<4;
|
||||
const uint64_t RInverse = 1<<4;
|
||||
const uint64_t RHidden = 1<<5;
|
||||
const uint64_t RStrikethrough = 1<<6;
|
||||
const uint64_t RResetBold = 1<<7;
|
||||
const uint64_t RResetDim = 1<<8;
|
||||
const uint64_t RResetItalic = 1<<9;
|
||||
const uint64_t RResetUnderline = 1<<10;
|
||||
const uint64_t RResetBlink = 1<<11;
|
||||
const uint64_t RResetInverse = 1<<12;
|
||||
const uint64_t RResetHidden = 1<<13;
|
||||
const uint64_t RResetStrikethrough = 1<<14;
|
||||
const uint64_t RColor16 = 1<<15;
|
||||
const uint64_t RColor256 = 1<<16;
|
||||
const uint64_t RColorRGB = 1<<17;
|
||||
const uint64_t RForegroundColor = 1<<18;
|
||||
const uint64_t RBackgroundColor = 1<<19;
|
||||
const uint64_t RDefaultColor = 1<<20;
|
||||
|
||||
class Rendition {
|
||||
uint64_t flags = 0;
|
||||
uint32_t color = 0;
|
||||
public:
|
||||
Rendition() {};
|
||||
Rendition(uint64_t f) : flags(f) {};
|
||||
Rendition(uint64_t f, uint8_t c) : flags(f | RColor256), color(c) {
|
||||
if ((flags & (RForegroundColor | RBackgroundColor)) == 0)
|
||||
flags |= RForegroundColor;
|
||||
};
|
||||
Rendition(uint64_t f, uint8_t r, uint8_t g, uint8_t b) : flags(f | RColorRGB) {
|
||||
if ((flags & (RForegroundColor | RBackgroundColor)) == 0)
|
||||
flags |= RForegroundColor;
|
||||
|
||||
this->color = (uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b << 0;
|
||||
}
|
||||
std::string Compile() {
|
||||
std::ostringstream s;
|
||||
s << Mutil::Console::General::Codes::ESC << '[';
|
||||
|
||||
if (flags == RNormal) {
|
||||
s << "0m";
|
||||
return s.str();
|
||||
}
|
||||
|
||||
if ((flags & RBold) == RBold)
|
||||
s << "1" << ";";
|
||||
|
||||
if ((flags & RDim) == RDim)
|
||||
s << "2" << ";";
|
||||
|
||||
if ((flags & RItalic) == RItalic)
|
||||
s << "3" << ";";
|
||||
|
||||
if ((flags & RUnderline) == RUnderline)
|
||||
s << "4" << ";";
|
||||
|
||||
if ((flags & RBlink) == RBlink)
|
||||
s << "5" << ";";
|
||||
|
||||
if ((flags & RInverse) == RInverse)
|
||||
s << "7" << ";";
|
||||
|
||||
if ((flags & RHidden) == RHidden)
|
||||
s << "8" << ";";
|
||||
|
||||
if ((flags & RStrikethrough) == RStrikethrough)
|
||||
s << "9" << ";";
|
||||
|
||||
if ((flags & RResetBold) == RResetBold)
|
||||
s << "22" << ";";
|
||||
|
||||
if ((flags & RResetDim) == RResetDim)
|
||||
s << "22" << ";";
|
||||
|
||||
if ((flags & RResetItalic) == RResetItalic)
|
||||
s << "23" << ";";
|
||||
|
||||
if ((flags & RResetUnderline) == RResetUnderline)
|
||||
s << "24" << ";";
|
||||
|
||||
if ((flags & RResetBlink) == RResetBlink)
|
||||
s << "25" << ";";
|
||||
|
||||
if ((flags & RResetInverse) == RResetInverse)
|
||||
s << "27" << ";";
|
||||
|
||||
if ((flags & RResetHidden) == RResetHidden)
|
||||
s << "28" << ";";
|
||||
|
||||
if ((flags & RResetStrikethrough) == RResetStrikethrough)
|
||||
s << "29" << ";";
|
||||
|
||||
if ((flags & RForegroundColor) == RForegroundColor)
|
||||
s << "38" << ";";
|
||||
|
||||
if ((flags & RBackgroundColor) == RBackgroundColor)
|
||||
s << "48" << ";";
|
||||
|
||||
if ((flags & RColor256) == RColor256)
|
||||
s << "5" << ";" << std::to_string(color) << ";";
|
||||
|
||||
if ((flags & RColorRGB) == RColorRGB)
|
||||
s << "2" << ";" << std::to_string((color >> 16) & 0x000000ff) << ";" << std::to_string((color >> 8) & 0x000000ff) << ";" << std::to_string((color >> 0) & 0x000000ff) << ";";
|
||||
|
||||
if ((flags & (RDefaultColor | RForegroundColor)) == (RDefaultColor | RForegroundColor))
|
||||
s << "39" << ";";
|
||||
|
||||
if ((flags & (RDefaultColor | RBackgroundColor)) == (RDefaultColor | RBackgroundColor))
|
||||
s << "49" << ";";
|
||||
|
||||
std::string c = s.str();
|
||||
c.back() = 'm';
|
||||
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Mutil::Console::Functions {
|
||||
|
@@ -17,7 +17,8 @@ namespace Mutil::Logging {
|
||||
std::ostream &os = std::clog;
|
||||
/// Lambda formatting function, primarily for storing a format string in a versatile way, users allowed to supply their own.
|
||||
std::function<std::string()> λPrefix;
|
||||
std::function<std::string(const std::string_view)> λMessage;
|
||||
//std::function<std::string(const std::string_view)> λMessage;
|
||||
std::function<std::string(const std::string)> λMessage;
|
||||
std::function<std::string()> λSuffix;
|
||||
public:
|
||||
/// Default constructor, just simple messages to be written to console
|
||||
@@ -28,12 +29,13 @@ namespace Mutil::Logging {
|
||||
/// Full construction
|
||||
LoggerObj(std::ostream &os,
|
||||
std::function<std::string()> λprefix,
|
||||
std::function<std::string(const std::string_view)> λmessage,
|
||||
std::function<std::string(const std::string)> λmessage,
|
||||
std::function<std::string()> λsuffix
|
||||
) : os(os), λPrefix(λprefix), λMessage(λmessage), λSuffix(λsuffix) {};
|
||||
public:
|
||||
/// Send a simple log message
|
||||
void operator()(const std::string_view message) {
|
||||
//void operator()(const std::string_view message) {
|
||||
void operator()(const std::string message) {
|
||||
//std::ostringstream oss;
|
||||
|
||||
λPrefix && os << λPrefix();
|
||||
|
68
main.cpp
68
main.cpp
@@ -3,61 +3,25 @@
|
||||
#include <Console.hpp>
|
||||
|
||||
int main() {
|
||||
Mutil::Logging::LoggerObj lo;
|
||||
lo("Hello world!!!!");
|
||||
/*
|
||||
Mutil::Logging::Info I;
|
||||
Mutil::Logging::Error E;
|
||||
Mutil::Logging::Verbose V;
|
||||
Mutil::Logging::Debug D;
|
||||
I("Something...");
|
||||
E("Something...");
|
||||
V("Something...");
|
||||
D("Something...");
|
||||
*/
|
||||
//std::cout << (char)0x1b << (char)0x5b << "33m" << "BULLOCKS" << '\n';
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::TextStyle::Underline,
|
||||
Mutil::Console::Graphics::ColorFormat::SetForegroundColor,
|
||||
Mutil::Console::Graphics::ColorFormat::ColorRGB, 252, 186, 3,
|
||||
});
|
||||
std::cout << uint16_t(69) << std::endl;
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::TextStyle::Reset,
|
||||
Mutil::Console::Graphics::Color16::Green});
|
||||
std::cout << uint16_t(70) << std::endl;
|
||||
std::function<std::string()> λprefix = [] {
|
||||
return Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RItalic, 252, 186, 3).Compile() + "--> " + Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RNormal).Compile();
|
||||
};
|
||||
std::function<std::string(const std::string)> λmessage = [](const std::string m) {
|
||||
return Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RUnderline, 74).Compile() + m + Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RNormal).Compile();
|
||||
};
|
||||
//std::function<std::string()> λsuffix = [] {
|
||||
// return " 0";
|
||||
//};
|
||||
|
||||
Mutil::Logging::LoggerObj l(std::cout, []{
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::TextStyle::Reset,
|
||||
Mutil::Console::Graphics::TextStyle::Italic,
|
||||
Mutil::Console::Graphics::TextStyle::Underline,});
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::ColorFormat::SetForegroundColor,
|
||||
Mutil::Console::Graphics::ColorFormat::ColorRGB, 252, 186, 3,
|
||||
});
|
||||
return "--> ";
|
||||
}, [] (const std::string_view m) {
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
//Mutil::Console::Graphics::TextStyle::Reset,
|
||||
Mutil::Console::Graphics::TextStyle::Underline,
|
||||
Mutil::Console::Graphics::TextStyle::Bold,
|
||||
Mutil::Console::Graphics::Color16::Blue,
|
||||
});
|
||||
|
||||
return std::format("<{}>", m);
|
||||
}, [] {
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::TextStyle::Reset,
|
||||
});
|
||||
return "==";
|
||||
}
|
||||
);
|
||||
Mutil::Logging::LoggerObj l(std::cout, λprefix, λmessage, nullptr);
|
||||
|
||||
l("Hello world");
|
||||
//l << "Something...." << "ass" << " " << "pussy";
|
||||
l << "DSDSAD" << "dddddd" << "DDSDDAWSH";
|
||||
l << "ddddd";
|
||||
Mutil::Console::Graphics::Rendition r(Mutil::Console::Graphics::RItalic, 252, 186, 3);
|
||||
std::string c = r.Compile();
|
||||
std::cout << c << "ass" << std::endl;
|
||||
|
||||
std::cout << Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RBold | Mutil::Console::Graphics::RItalic, 160, 186, 3).Compile() << "SHIIIIIIT" << Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RNormal).Compile() << std::endl;
|
||||
|
||||
//Desktop::Browser::OpenURL("https://git.redacted.cc/maxine/mutil");
|
||||
//Mutil::Console::Graphics::SGARG a = Mutil::Console::Graphics::TextStyle::Underline
|
||||
}
|
||||
|
Reference in New Issue
Block a user