Compare commits
5 Commits
0b7fe2ccfc
...
4ae78f8de0
Author | SHA1 | Date | |
---|---|---|---|
4ae78f8de0 | |||
9e41188e8d | |||
5030afc04e | |||
97a9d37417 | |||
c2539b4d27 |
@@ -31,23 +31,23 @@ namespace Mutil::Console::Graphics {
|
||||
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;
|
||||
const uint64_t RInverse = 1<<5;
|
||||
const uint64_t RHidden = 1<<6;
|
||||
const uint64_t RStrikethrough = 1<<7;
|
||||
const uint64_t RResetBold = 1<<8;
|
||||
const uint64_t RResetDim = 1<<9;
|
||||
const uint64_t RResetItalic = 1<<10;
|
||||
const uint64_t RResetUnderline = 1<<11;
|
||||
const uint64_t RResetBlink = 1<<12;
|
||||
const uint64_t RResetInverse = 1<<13;
|
||||
const uint64_t RResetHidden = 1<<14;
|
||||
const uint64_t RResetStrikethrough = 1<<15;
|
||||
const uint64_t RColor16 = 1<<16;
|
||||
const uint64_t RColor256 = 1<<17;
|
||||
const uint64_t RColorRGB = 1<<18;
|
||||
const uint64_t RForegroundColor = 1<<19;
|
||||
const uint64_t RBackgroundColor = 1<<20;
|
||||
const uint64_t RDefaultColor = 1<<21;
|
||||
|
||||
class Rendition {
|
||||
uint64_t flags = 0;
|
||||
@@ -65,6 +65,8 @@ namespace Mutil::Console::Graphics {
|
||||
|
||||
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 << '[';
|
||||
@@ -147,17 +149,73 @@ namespace Mutil::Console::Graphics {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class String {
|
||||
std::string str;
|
||||
Rendition rendition;
|
||||
public:
|
||||
String(std::string s) : str(s) {}
|
||||
String(std::string s, Rendition r) : str(s), rendition(r) {};
|
||||
void Style(Rendition r) { rendition = r;};
|
||||
std::string Render() { return rendition.Compile() + str + Rendition(RNormal).Compile(); };
|
||||
std::string Render(Rendition r) {
|
||||
Style(r);
|
||||
return Render();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Mutil::Console::Functions {
|
||||
void CursorUp(uint n) {};
|
||||
void call(std::ostream &os, const std::string& arg, const char& func) {
|
||||
std::ostringstream s;
|
||||
s << General::Codes::ESC << '[' << arg << func;
|
||||
os << s.str();
|
||||
}
|
||||
|
||||
class Display {
|
||||
std::ostream &os = std::cout;
|
||||
public:
|
||||
Display() {};
|
||||
Display(std::ostream &os) : os(os) {};
|
||||
void A(uint n = 1) { call(os, std::to_string(n), 'A'); };
|
||||
void B(uint n = 1) { call(os, std::to_string(n), 'B'); };
|
||||
void C(uint n = 1) { call(os, std::to_string(n), 'C'); };
|
||||
void D(uint n = 1) { call(os, std::to_string(n), 'D'); };
|
||||
void E(uint n = 1) { call(os, std::to_string(n), 'E'); };
|
||||
void F(uint n = 1) { call(os, std::to_string(n), 'F'); };
|
||||
void G(uint n = 1) { call(os, std::to_string(n), 'G'); };
|
||||
void H(uint n = 0, uint m = 0) { call(os, std::format("{};{}",n,m), 'H'); };
|
||||
void J(uint n = 0) { call(os, std::to_string(n), 'J'); };
|
||||
void K(uint n = 0) { call(os, std::to_string(n), 'K'); };
|
||||
void S(uint n = 1) { call(os, std::to_string(n), 'S'); };
|
||||
void T(uint n = 1) { call(os, std::to_string(n), 'T'); };
|
||||
void s() { os << General::Codes::ESC << "7"; };
|
||||
void u() { os << General::Codes::ESC << "8"; };
|
||||
void m(Graphics::Rendition r) { os << r.Compile(); };
|
||||
//Display& Write(const char* in) {
|
||||
// os << in;
|
||||
// return *this;
|
||||
//}
|
||||
|
||||
template<typename In>
|
||||
friend std::ostream& operator<<(Display& d, In in);
|
||||
};
|
||||
|
||||
template<typename In>
|
||||
std::ostream& operator<<(Display& d, In in) {
|
||||
return d.os << in;
|
||||
}
|
||||
|
||||
|
||||
std::string CursorUp(uint n) { return std::format("{}[{}A", "\x1b[", n); };
|
||||
void CursorDown(uint n) {};
|
||||
void CursorForward(uint n) {};
|
||||
void CursorBack(uint n) {};
|
||||
void CursorNextLine(uint n) {};
|
||||
void CursorPreviousLine(uint n) {};
|
||||
void CursorHorizontalAbsolute(uint n) {};
|
||||
void CursorPosition(uint n, uint m) {};
|
||||
std::string CursorPosition(uint n, uint m) { return std::format("\x1b[{};{}H", n, m); };
|
||||
void RequestCursorPosition() {};
|
||||
void EraseInDisplay(uint n) {};
|
||||
void EraseInLine(uint n) {};
|
||||
|
@@ -15,101 +15,43 @@ namespace Mutil::Logging {
|
||||
private:
|
||||
/// Output stream, default std::clog.
|
||||
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)> λMessage;
|
||||
std::function<std::string()> λSuffix;
|
||||
/// Lambda function on message, can be used for formatting
|
||||
std::function<std::string(const std::string_view)> λMessage;
|
||||
public:
|
||||
/// Default constructor, just simple messages to be written to console
|
||||
/// Default constructor, just simple messages to be written to console stderr
|
||||
LoggerObj() {};
|
||||
/// Construct with specified output stream
|
||||
LoggerObj(std::ostream &os);
|
||||
|
||||
LoggerObj(std::ostream &os) : os(os) {};
|
||||
/// Full construction
|
||||
LoggerObj(std::ostream &os,
|
||||
std::function<std::string()> λprefix,
|
||||
std::function<std::string(const std::string)> λmessage,
|
||||
std::function<std::string()> λsuffix
|
||||
) : os(os), λPrefix(λprefix), λMessage(λmessage), λSuffix(λsuffix) {};
|
||||
LoggerObj(std::ostream &os, std::function<std::string(const std::string_view)> λMessage) : os(os), λMessage(λMessage) {};
|
||||
public:
|
||||
/// Send a simple log message
|
||||
//void operator()(const std::string_view message) {
|
||||
void operator()(const std::string message) {
|
||||
//std::ostringstream oss;
|
||||
|
||||
λPrefix && os << λPrefix();
|
||||
(λMessage && os << λMessage(message)) || os << message;
|
||||
λSuffix && os << λSuffix();
|
||||
|
||||
//os << oss.str() << std::endl;
|
||||
|
||||
void operator()(const std::string_view message) {
|
||||
λMessage ? os << λMessage(message) : os << message;
|
||||
os << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// Send a formatted/complex log message
|
||||
template<typename... Args>
|
||||
void operator()(const std::format_string<Args...> fmt, Args&&... args) {
|
||||
//std::ostringstream oss;
|
||||
std::string m = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
λPrefix && os << λPrefix();
|
||||
(λMessage && os << λMessage(m)) || os << m;
|
||||
λSuffix && os << λSuffix();
|
||||
|
||||
//os << oss.str() << std::endl;
|
||||
|
||||
λMessage ? os << λMessage(m) : os << m;
|
||||
os << std::endl;
|
||||
};
|
||||
|
||||
/// Send log messages using logger as a stream
|
||||
//template<typename In>
|
||||
//LoggerObj& operator<<(In message) {
|
||||
// λMessage ? os << λMessage(message) : os << message;
|
||||
// os << std::endl;
|
||||
// return *this;
|
||||
//};
|
||||
|
||||
template<typename In>
|
||||
LoggerObj& operator<<(In message) {
|
||||
//std::ostringstream oss;
|
||||
//oss << message;
|
||||
//operator()(oss.str());
|
||||
|
||||
//(λ && os << λ() << message) ||
|
||||
//os << message;
|
||||
//return os;
|
||||
|
||||
λPrefix && os << λPrefix();
|
||||
(λMessage && os << λMessage(message)) || os << message;
|
||||
λSuffix && os << λSuffix();
|
||||
λMessage ? os << λMessage(message) : os << message;
|
||||
os << std::endl;
|
||||
|
||||
return *this;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
class Info : public LoggerObj {
|
||||
public:
|
||||
Info() : LoggerObj("[I] | ") {};
|
||||
};
|
||||
|
||||
class Warning : public LoggerObj {
|
||||
public:
|
||||
Warning() : LoggerObj("[W] | ") {};
|
||||
};
|
||||
|
||||
class Error : public LoggerObj {
|
||||
public:
|
||||
Error() : LoggerObj("[E] | ") {};
|
||||
};
|
||||
|
||||
class Verbose : public LoggerObj {
|
||||
public:
|
||||
Verbose() : LoggerObj("[V] | ") {};
|
||||
};
|
||||
|
||||
class Debug : public LoggerObj {
|
||||
public:
|
||||
Debug() : LoggerObj("[D] | ") {};
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
|
115
main.cpp
115
main.cpp
@@ -2,31 +2,30 @@
|
||||
#include <Desktop.hpp>
|
||||
#include <Console.hpp>
|
||||
#include <source_location>
|
||||
#include <unistd.h>
|
||||
|
||||
class Debug : public Mutil::Logging::LoggerObj {
|
||||
static std::string λMessage(std::string m) {
|
||||
return Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RItalic, 135).Compile() + std::format("[D] {}", m) + Mutil::Console::Graphics::Rendition().Compile();
|
||||
};
|
||||
std::string NormalRen = Mutil::Console::Graphics::Rendition().Compile();
|
||||
std::string MessageRen = Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RItalic, 135).Compile();
|
||||
std::string TraceRen = Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RBold, 241).Compile();
|
||||
public:
|
||||
Debug() : LoggerObj(std::cout, nullptr, λMessage, nullptr) {};
|
||||
Debug() : LoggerObj(std::cout, [this](const std::string_view m) {return std::format("{}{}[D] {}{}", NormalRen, MessageRen, m, NormalRen); }) {};
|
||||
void Trace(const std::source_location &location = std::source_location::current()) {
|
||||
Mutil::Console::Graphics::Rendition r(Mutil::Console::Graphics::RBold, 241);
|
||||
this->operator()("{}{} @ {}:{}", r.Compile(), location.function_name(), location.file_name(), location.line());
|
||||
this->operator()("{}{} @ {}:{}", TraceRen, location.function_name(), location.file_name(), location.line());
|
||||
};
|
||||
};
|
||||
|
||||
int main() {
|
||||
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_view)> λmessage = [](const std::string_view m) {
|
||||
return std::format("{}{} {}{}{}",
|
||||
Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RItalic, 252, 186, 3).Compile(),
|
||||
"-->",
|
||||
Mutil::Console::Graphics::Rendition(Mutil::Console::Graphics::RUnderline, 74).Compile(),
|
||||
m,
|
||||
Mutil::Console::Graphics::Rendition().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, λprefix, λmessage, nullptr);
|
||||
Mutil::Logging::LoggerObj l(std::cout, λmessage);
|
||||
|
||||
l("Hello world");
|
||||
l << "something" << "something." << "something..";
|
||||
@@ -39,9 +38,93 @@ int main() {
|
||||
Debug d;
|
||||
d << "DEBUGGGGING";
|
||||
d.Trace();
|
||||
Mutil::Console::Graphics::String s("balls");
|
||||
std::cout << s.Render({Mutil::Console::Graphics::RItalic}) << std::endl;
|
||||
|
||||
//d << Mutil::Console::Functions::CursorUp(6);
|
||||
//d.Trace();
|
||||
|
||||
//std::cout << "\x1b[2J" << Mutil::Console::Functions::CursorPosition(1, 3) << "AAAAAAAAAAAAAAAAA" << std::endl;
|
||||
|
||||
//std::cout << "\x1b[2J";
|
||||
//std::cout << Mutil::Console::Functions::CursorPosition(1, 39
|
||||
//) << "AAAAAAAA";
|
||||
//std::cout << Mutil::Console::Functions::CursorPosition(2, 35) << "AAAA";
|
||||
//std::cout << Mutil::Console::Functions::CursorPosition(3, 31) << "AAAA";
|
||||
// std::cout << Mutil::Console::Functions::CursorPosition(4, 29) << "AA";
|
||||
// std::cout << std::endl;
|
||||
|
||||
Mutil::Console::Functions::Display display;
|
||||
display.J(2);
|
||||
display.H();
|
||||
display.m({Mutil::Console::Graphics::RUnderline,70});
|
||||
//const char* womp = "womp womp";
|
||||
//std::cout << womp << std::endl;
|
||||
|
||||
|
||||
display << "ASS" << std::endl;
|
||||
display << "DICK" << "FUCK" << std::endl;
|
||||
display.m({});
|
||||
|
||||
//display.H(12, 40);
|
||||
//display << "λ" << std::endl;
|
||||
|
||||
display.J(2);
|
||||
//display << "\x1b[?47h";
|
||||
for (uint i = 1; i < 24; i++) {
|
||||
//display.J(2);
|
||||
Mutil::Console::Graphics::Rendition r(0, i);
|
||||
display.H(i, i+1);
|
||||
display.m(r);
|
||||
display << std::format("F{}", i) << "λ" << std::endl;
|
||||
// 1 second = 1000000 microseconds
|
||||
// 24 frames (technically)
|
||||
// 1000000 / 24
|
||||
// 41666 microseconds between frames roughly
|
||||
usleep(41666*2);
|
||||
display.A();
|
||||
display.m(r);
|
||||
display.G(i+std::string(std::format("F{}λ", i)).size()-1);
|
||||
usleep(41666*2);
|
||||
display.K();
|
||||
for (uint j = i+std::string(std::format("F{}λ", i)).size()-1; j < 80; j++) {
|
||||
display << "-" << std::endl;
|
||||
display.A();
|
||||
display.G(j);
|
||||
usleep(41666/2);
|
||||
}
|
||||
display << "λ";
|
||||
display << '\n';
|
||||
//display.K(0);
|
||||
|
||||
}
|
||||
display.m({});
|
||||
//display << '\n';
|
||||
//display << "\x1b[?47l";
|
||||
|
||||
|
||||
//display << "\x1b[?47h";
|
||||
////display.H();
|
||||
////display.J(2);
|
||||
////display.s();
|
||||
////display.H(24,80);
|
||||
////display.m({Mutil::Console::Graphics::RUnderline, 27});
|
||||
////display << "SomethingSomethingAsshole" << std::endl;
|
||||
//display.H(3,3);
|
||||
////display.m({});
|
||||
////display.u();
|
||||
//display.s();
|
||||
//display.H(24,80);
|
||||
//display << "0" << std::endl;
|
||||
//display.u();
|
||||
//display << "\x1b[?47l";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//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