From 37a919be1599150da62708c7207ab0485d4960fd Mon Sep 17 00:00:00 2001 From: maxine Date: Mon, 23 Jun 2025 13:54:24 -0400 Subject: [PATCH] first commit --- CMakeLists.txt | 39 ++++++++++++++++++ include/Console.hpp | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/Logging.hpp | 88 +++++++++++++++++++++++++++++++++++++++++ main.cpp | 16 ++++++++ 4 files changed, 239 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 include/Console.hpp create mode 100644 include/Logging.hpp create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1d4c0e4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.28) +project(mutil) + +set(CMAKE_CXX_STANDARD 20) + +if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed!") +endif() + +file(GLOB_RECURSE mutil_HEADERS "include/*.h" "include/*.hpp") +##file(GLOB_RECURSE mutil_SRC "src/*.c" "src/*.cpp") + + + + + +##if (UNIX) +## add_library(mutil SHARED ${mutil_SRC}) +##endif() + +## Untested for now +##if (WIN32) +## add_library(mutil STATIC ${mutil_SRC}) +##endif() + +add_library(mutil INTERFACE) + +set_target_properties(mutil PROPERTIES LINKER_LANGUAGE CXX) + +##target_include_directories(mutil PUBLIC "include") +target_include_directories(mutil INTERFACE "include") + +install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) +install(FILES ${mutil_HEADERS} DESTINATION include/${PROJECT_NAME}) + + +add_executable(mutilTest main.cpp) +##target_link_libraries(mutilTest PUBLIC mutil) +target_link_libraries(mutilTest PRIVATE mutil) diff --git a/include/Console.hpp b/include/Console.hpp new file mode 100644 index 0000000..1e6c45e --- /dev/null +++ b/include/Console.hpp @@ -0,0 +1,96 @@ +// +// Created by maxine on 6/16/25. +// + +#pragma once + +#include +#include +#include + +namespace Mutil::Console::Sequences { + const char ESC = 0x1b; + const char CSI = 0x9b; + const char DCS = 0x90; + const char OSC = 0x9d; +} + +namespace Mutil::Console::General { + const char BEL = 0x07; + const char BS = 0x08; + const char HT = 0x09; + const char LF = 0x0A; + const char VT = 0x0B; + const char FF = 0x0C; + const char CR = 0x0D; + using Mutil::Console::Sequences::ESC; + const char DEL = 0x7f; +} + +namespace Mutil::Console::Cursor { + class Movement { + public: + void Home() {}; + void LnCol(uint64_t line, uint64_t column) {}; + void Up(uint64_t lines) {}; + void Down(uint64_t lines) {}; + void Right(uint64_t columns) {}; + void Left(uint64_t columns) {}; + void NextLn(uint64_t lines) {}; + void PrevLn(uint64_t lines) {}; + void JmpCol(uint64_t column) {}; + std::pair Pos() {}; + void Save() {}; + void Restore() {}; + }; +} + +namespace Mutil::Console::Erase { + +} + +namespace Mutil::Console::Graphics { + class Format { + void Reset() {}; + void Bold() {}; + void ResetBold() {}; + void Dim() {}; + void ResetDim() {}; + void Italic() {}; + void ResetItalic() {}; + void Underline() {}; + void ResetUnderline() {}; + void Blink() {}; + void ResetBlink() {}; + void Inverse() {}; + void ResetInverse() {}; + void Hidden() {}; + void ResetHidden() {}; + void Strikethrough() {}; + void ResetStrikethrough() {}; + }; + + // Color 16 +/* const uint8_t Black = 30; + const uint8_t Red = 31; + const uint8_t Green = 32; + const uint8_t Yellow = 33; + const uint8_t Blue = 34; + const uint8_t Magenta = 35; + const uint8_t Cyan = 36; + const uint8_t White = 37; + const uint8_t Default = 39; + const uint8_t BlackBG = 40; + const uint8_t + const uint8_t + const uint8_t + const uint8_t + const uint8_t + const uint8_t + + class Color16 { + + };*/ + + +} \ No newline at end of file diff --git a/include/Logging.hpp b/include/Logging.hpp new file mode 100644 index 0000000..c13a4d5 --- /dev/null +++ b/include/Logging.hpp @@ -0,0 +1,88 @@ +// +// Created by maxine on 6/16/25. +// + +#pragma once + +#include +#include +#include + +namespace Mutil::Logging { + /// Logger object for constructing loggers. + class LoggerObj { + 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 λ; + public: + /// Default constructor, just simple messages to be written to console + LoggerObj() {}; + /// Construct with specified output stream + LoggerObj(std::ostream &os); + /// Construct with a custom, formatted prefix applied to every message, such as "* Mutil Logging >> message". + template + LoggerObj(const std::format_string fmt, Args&&... args) { + λ = [fmt, args...](){ + return std::vformat(fmt.get(), std::make_format_args(args...)); + }; + } + /// Construct with a custom lambda formatting function + LoggerObj(std::function λ) : λ(λ) {}; + /// Construct with a specified output stream and custom formatting function + LoggerObj(std::ostream &os, std::function λ) : λ(λ) {}; + public: + /// If provided only runs formatting function, formatting function may retrieve data for its own messages. + void operator()() { + λ && os << λ(); + } + + /// Send a simple log message + void operator()(const std::string_view message) { + (λ && os << λ() << message << '\n') || + os << message << '\n'; + } + + /// Send a formatted/complex log message + template + void operator()(const std::format_string fmt, Args&&... args) { + (λ && os << λ() << std::vformat(fmt.get(), std::make_format_args(args...)) << '\n') || + os << std::vformat(fmt.get(), std::make_format_args(args...)) << '\n'; + }; + + /// Send log messages using logger as a stream + template + std::ostream& operator<<(In message) { + (λ && os << λ() << message) || + os << message; + return os; + }; + }; + + 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] | ") {}; + }; +} + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..dfd4aba --- /dev/null +++ b/main.cpp @@ -0,0 +1,16 @@ +#include + +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'; + //std::cout << 0x1b5b << "33m" << "BALLS" << '\n'; +}