initial commit

This commit is contained in:
asrael 2025-08-13 15:04:49 -05:00
commit c18896def0
No known key found for this signature in database
GPG key ID: 2786557804DFAE24
30 changed files with 4183 additions and 0 deletions

83
src/pxl8_macros.h Normal file
View file

@ -0,0 +1,83 @@
#pragma once
#include <stdio.h>
#include <time.h>
#define PXL8_LOG_ERROR "\033[38;2;251;73;52m"
#define PXL8_LOG_SUCCESS "\033[38;2;254;128;25m"
#define PXL8_LOG_WARN "\033[38;2;250;189;47m"
#define PXL8_LOG_INFO "\033[38;2;184;187;38m"
#define PXL8_LOG_DEBUG "\033[38;2;131;165;152m"
#define PXL8_LOG_TRACE "\033[38;2;211;134;155m"
#define PXL8_LOG_MUTED "\033[38;2;168;153;132m"
#define PXL8_LOG_RESET "\033[0m"
static inline void pxl8_log_timestamp(char* buffer, size_t size) {
time_t now = time(NULL);
struct tm* tm_info = localtime(&now);
strftime(buffer, size, "%H:%M:%S", tm_info);
}
#ifdef DEBUG
#ifndef PXL8_ENABLE_DEBUG_LOGS
#define PXL8_ENABLE_DEBUG_LOGS 1
#endif
#if PXL8_ENABLE_DEBUG_LOGS
#define pxl8_debug(...) \
do { \
char timestamp[16]; \
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
fprintf(stderr, PXL8_LOG_DEBUG "[%s DEBUG]" PXL8_LOG_RESET \
" %s:%d: ", timestamp, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#define pxl8_trace(...) \
do { \
char timestamp[16]; \
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
fprintf(stderr, PXL8_LOG_TRACE "[%s TRACE]" PXL8_LOG_RESET \
" %s:%d: ", timestamp, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#else
#define pxl8_debug(...)
#define pxl8_trace(...)
#endif
#else
#define pxl8_debug(...)
#define pxl8_trace(...)
#endif
#define pxl8_error(...) \
do { \
char timestamp[16]; \
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
fprintf(stderr, PXL8_LOG_ERROR "[%s ERROR]" PXL8_LOG_RESET \
" %s:%d: ", timestamp, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#define pxl8_warn(...) \
do { \
char timestamp[16]; \
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
fprintf(stderr, PXL8_LOG_WARN "[%s WARN]" PXL8_LOG_RESET \
" %s:%d: ", timestamp, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#define pxl8_info(...) \
do { \
char timestamp[16]; \
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
fprintf(stdout, PXL8_LOG_INFO "[%s INFO]" PXL8_LOG_RESET \
" ", timestamp); \
fprintf(stdout, __VA_ARGS__); \
fprintf(stdout, "\n"); \
} while(0)