SGR, logging
This commit is contained in:
@@ -24,10 +24,8 @@ namespace Mutil::Console::General {
|
||||
}
|
||||
|
||||
namespace Mutil::Console::Graphics {
|
||||
typedef uint8_t SGARG;
|
||||
|
||||
// Text styling
|
||||
enum class TextStyle : SGARG {
|
||||
enum TextStyle : uint8_t {
|
||||
Reset = 0,
|
||||
Bold,
|
||||
Dim,
|
||||
@@ -45,14 +43,14 @@ namespace Mutil::Console::Graphics {
|
||||
ResetInverse = 27,
|
||||
ResetHidden,
|
||||
ResetStrikethrough,
|
||||
SetForegroundColor = 38,
|
||||
|
||||
DefaultForegroundColor = 39,
|
||||
SetBackgroundColor = 48,
|
||||
|
||||
DefaultBackgroundColor = 49,
|
||||
};
|
||||
|
||||
// Color 16
|
||||
enum class Color16 : SGARG {
|
||||
enum Color16 : uint8_t {
|
||||
Black = 30,
|
||||
Red,
|
||||
Green,
|
||||
@@ -71,9 +69,11 @@ namespace Mutil::Console::Graphics {
|
||||
WhiteBG,
|
||||
};
|
||||
|
||||
enum class ColorFormats : SGARG {
|
||||
enum ColorFormat : uint8_t {
|
||||
ColorRGB = 2,
|
||||
Color256 = 5,
|
||||
SetForegroundColor = 38,
|
||||
SetBackgroundColor = 48,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -93,19 +93,20 @@ namespace Mutil::Console::Functions {
|
||||
void ScrollDown(uint n) {};
|
||||
void SaveCursorPosition() {};
|
||||
void RestoreCursorPosition() {};
|
||||
void SelectGraphicsRendition(std::initializer_list<Mutil::Console::Graphics::SGARG> args) {
|
||||
|
||||
void SelectGraphicsRendition(std::initializer_list<uint8_t> args) {
|
||||
if (empty(args)) { return; };
|
||||
|
||||
std::stringstream s;
|
||||
s << (char)Mutil::Console::General::Codes::ESC << '[';
|
||||
|
||||
for (Mutil::Console::Graphics::SGARG a : args) {
|
||||
for (uint8_t a : args) {
|
||||
//std::cout << (uint16_t)a << std::endl;
|
||||
if (a == *std::prev(args.end())) {
|
||||
s << (uint16_t)a;
|
||||
s << std::to_string(a);
|
||||
break;
|
||||
}
|
||||
s << (uint16_t)a << ';';
|
||||
s << std::to_string(a) << ';';
|
||||
}
|
||||
s << 'm';
|
||||
|
||||
|
@@ -31,7 +31,7 @@ namespace Mutil::Logging {
|
||||
/// Construct with a custom lambda formatting function
|
||||
LoggerObj(std::function<std::string(void)> λ) : λ(λ) {};
|
||||
/// Construct with a specified output stream and custom formatting function
|
||||
LoggerObj(std::ostream &os, std::function<std::string(void)> λ) : λ(λ) {};
|
||||
LoggerObj(std::ostream &os, std::function<std::string(void)> λ) : os(os), λ(λ) {};
|
||||
public:
|
||||
/// If provided only runs formatting function, formatting function may retrieve data for its own messages.
|
||||
void operator()() {
|
||||
|
27
main.cpp
27
main.cpp
@@ -15,12 +15,29 @@ int main() {
|
||||
D("Something...");
|
||||
//std::cout << (char)0x1b << (char)0x5b << "33m" << "BULLOCKS" << '\n';
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
(uint8_t)Mutil::Console::Graphics::TextStyle::Underline,
|
||||
(uint8_t)Mutil::Console::Graphics::TextStyle::SetForegroundColor,
|
||||
(uint8_t)Mutil::Console::Graphics::ColorFormats::ColorRGB, 252, 186, 3,
|
||||
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({(uint8_t)Mutil::Console::Graphics::TextStyle::Reset});
|
||||
Mutil::Console::Functions::SelectGraphicsRendition({
|
||||
Mutil::Console::Graphics::TextStyle::Reset,
|
||||
Mutil::Console::Graphics::Color16::Green});
|
||||
std::cout << uint16_t(70) << std::endl;
|
||||
Desktop::Browser::OpenURL("https://git.redacted.cc/maxine/mutil");
|
||||
|
||||
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 "--> ";
|
||||
});
|
||||
|
||||
l("Hello world");
|
||||
//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