first commit
This commit is contained in:
39
CMakeLists.txt
Normal file
39
CMakeLists.txt
Normal file
@@ -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)
|
96
include/Console.hpp
Normal file
96
include/Console.hpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
//
|
||||||
|
// Created by maxine on 6/16/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
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<uint64_t, uint64_t> 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 {
|
||||||
|
|
||||||
|
};*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
88
include/Logging.hpp
Normal file
88
include/Logging.hpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
//
|
||||||
|
// Created by maxine on 6/16/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <functional>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
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<std::string(void)> λ;
|
||||||
|
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<typename... Args>
|
||||||
|
LoggerObj(const std::format_string<Args...> 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<std::string(void)> λ) : λ(λ) {};
|
||||||
|
/// Construct with a specified output stream and custom formatting function
|
||||||
|
LoggerObj(std::ostream &os, std::function<std::string(void)> λ) : λ(λ) {};
|
||||||
|
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<typename... Args>
|
||||||
|
void operator()(const std::format_string<Args...> 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<typename In>
|
||||||
|
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] | ") {};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
16
main.cpp
Normal file
16
main.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include <Logging.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';
|
||||||
|
//std::cout << 0x1b5b << "33m" << "BALLS" << '\n';
|
||||||
|
}
|
Reference in New Issue
Block a user