Skip to content

Commit

Permalink
Document the color header and include it in the reference
Browse files Browse the repository at this point in the history
  • Loading branch information
agagniere committed Sep 3, 2024
1 parent 08e3268 commit 08061b8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
4 changes: 4 additions & 0 deletions book/pages/reference/arg_count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Counting arguments

:::{doxygenfile} arg_count.h
:::
4 changes: 4 additions & 0 deletions book/pages/reference/color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Terminal colors

:::{doxygenfile} color.h
:::
4 changes: 4 additions & 0 deletions book/pages/reference/fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Fold

:::{doxygenfile} fold.h
:::
3 changes: 3 additions & 0 deletions book/pages/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

:::{toctree}
token
arg_count
fold
color
log
:::
75 changes: 49 additions & 26 deletions include/blackmagic/color.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
#pragma once

/**
* @file
*
*/

#include "blackmagic/token.h" // STRINGIZE
#include "blackmagic/fold.h" // FOLD

/** @name Font style */
///@{
/**
* Reset font style.
* A color sequence with only `NORMAL` resets all style, color and background color
*/
#define NORMAL 0
#define BOLD 1
#define DIM 2
#define ITALIC 3
#define UNDERLINED 4
#define NEGATIVE 6
#define BOLD 1 /**< . */
#define DIM 2 /**< . */
#define ITALIC 3 /**< . */
#define UNDERLINED 4 /**< . */
#define NEGATIVE 6 /**< . */
///@}

#define BLACK 30
#define RED 31
#define GREEN 32
#define YELLOW 33
#define BLUE 34
#define PURPLE 35
#define CYAN 36
#define LIGHT_GREY 37
#define DEFAULT 39
#define WHITE 97
/** @name Font color */
///@{
#define BLACK 30 /**< . */
#define RED 31 /**< . */
#define GREEN 32 /**< . */
#define YELLOW 33 /**< . */
#define BLUE 34 /**< . */
#define PURPLE 35 /**< . */
#define CYAN 36 /**< . */
#define LIGHT_GREY 37 /**< . */
#define DEFAULT 39 /**< Reset font color */
#define WHITE 97 /**< . */
///@}

#define BG_BLACK 40
#define BG_RED 41
#define BG_GREEN 42
#define BG_YELLOW 43
#define BG_BLUE 44
#define BG_PURPLE 45
#define BG_CYAN 46
#define BG_LIGHT_GREY 47
#define BG_DEFAULT 49
#define BG_WHITE 107
/** @name Background color */
///@{
#define BG_BLACK 40 /**< . */
#define BG_RED 41 /**< . */
#define BG_GREEN 42 /**< . */
#define BG_YELLOW 43 /**< . */
#define BG_BLUE 44 /**< . */
#define BG_PURPLE 45 /**< . */
#define BG_CYAN 46 /**< . */
#define BG_LIGHT_GREY 47 /**< . */
#define BG_DEFAULT 49 /**< Reset background color */
#define BG_WHITE 107 /**< . */
///@}

#define COLOR_JOIN(A, B) A;B
/**
* Expands to a string literal containig an escape code setting the terminal color.
* @since 0.1
*/
#define COLOR(...) STRINGIZE(\e[FOLD(COLOR_JOIN __VA_OPT__(,) __VA_ARGS__)m)

#define COLOR_JOIN(A, B) A;B
4 changes: 3 additions & 1 deletion include/blackmagic/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* Choose the file to output logs to.
* What is expected is a `FILE*` like `stdout` or `stderr`.
*
* Defaults to `stderr`
*/
# define LOG_FILE stderr
Expand All @@ -33,6 +34,7 @@
/**
* Choose the compile-time log verbosity level.
* Logs that are strictly less critical that this level are removed before compilation.
*
* The default value is @ref LOG_LEVEL_TRACE for debug builds and @ref LOG_LEVEL_INFO for release builds that define `NDEBUG`.
*/
# define LOG_LEVEL LOG_LEVEL_TRACE
Expand Down Expand Up @@ -92,7 +94,7 @@
# define log_log(LEVEL, IGNORED, MESSAGE, ...) \
fprintf(LOG_FILE, "|" LEVEL "|`" __FILE__ "`|`%s`|" STRINGIZE(__LINE__) "|" MESSAGE "|\n", __func__ __VA_OPT__(, ) __VA_ARGS__)
#else
# define log_log(L, C, M, ...)
# define log_log(L, C, M, ...) /* Logs are disabled */
#endif

#if LOG_LEVEL >= LOG_LEVEL_FATAL
Expand Down

0 comments on commit 08061b8

Please sign in to comment.