Cthulhu  0.2.10
Cthulhu compiler collection
colour.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #pragma once
4 
5 #include <ctu_format_api.h>
6 
7 #include "core/compiler.h"
8 #include "core/analyze.h"
9 
10 #include <stdarg.h>
11 
13 
14 typedef struct arena_t arena_t;
15 
20 
22 typedef enum colour_t
23 {
31 
33 
36 
38 typedef struct colour_pallete_t
39 {
40  const char *colours[eColourCount];
41  STA_FIELD_STRING const char *reset;
43 
45 typedef struct format_context_t
46 {
50 
52 CT_FORMAT_API extern const colour_pallete_t kColourNone;
53 
55 CT_FORMAT_API extern const colour_pallete_t kColourDefault;
56 
64 CT_FORMAT_API const char *colour_get(IN_NOTNULL const colour_pallete_t *colours, IN_DOMAIN(<, eColourCount) colour_t idx);
65 
72 CT_FORMAT_API const char *colour_reset(IN_NOTNULL const colour_pallete_t *colours);
73 
82 CT_FORMAT_API char *colour_text(
83  format_context_t context,
85  IN_STRING const char *text);
86 
96 CT_FORMAT_API char *colour_format(
97  format_context_t context,
99  STA_FORMAT_STRING const char *fmt, ...);
100 
110 CT_FORMAT_API char *colour_vformat(
111  format_context_t context,
113  IN_STRING const char *fmt, va_list args);
114 
116 
STA_DECL char * colour_format(format_context_t context, colour_t idx, const char *fmt,...)
Definition: colour.c:65
#define CT_PUREFN
mark a function as pure, always returns the same value for the same arguments
Definition: analyze.h:228
#define STA_FIELD_STRING
annotate a field as being a null terminated string
#define IN_NOTNULL
annotate a parameter as not being null
#define STA_FORMAT_STRING
mark a function parameter as a printf format string
#define STA_RET_STRING
annotate the return value as a null terminated string
#define IN_DOMAIN(cmp, it)
annotate a parameter as being bounded by the expression of cmp and it
#define IN_STRING
annotate a parameter as being a null terminated string
colour_t
a colour code
Definition: colour.h:23
STA_RET_STRING colour_t STA_FORMAT_STRING const char * fmt
Definition: colour.h:99
STA_RET_STRING colour_t STA_FORMAT_STRING const char STA_RET_STRING CT_FORMAT_API char * colour_vformat(format_context_t context, colour_t idx, const char *fmt, va_list args)
format a string and add colour to it
Definition: colour.c:76
STA_RET_STRING CT_PUREFN CT_FORMAT_API const char * colour_get(const colour_pallete_t *colours, colour_t idx)
get a colours string form from a pallete
Definition: colour.c:39
CT_FORMAT_API const colour_pallete_t kColourNone
a colour pallete that applies no colours
Definition: colour.c:10
STA_RET_STRING STA_PRINTF(3, 4) CT_FORMAT_API char *colour_format(format_context_t context
format a string and add colour to it
STA_RET_STRING colour_t idx
Definition: colour.h:98
CT_FORMAT_API const colour_pallete_t kColourDefault
a colour pallete that applies ANSI VT100 colours
Definition: colour.c:24
STA_RET_STRING CT_PUREFN CT_FORMAT_API const char * colour_reset(const colour_pallete_t *colours)
get a reset string from a pallete
Definition: colour.c:48
STA_RET_STRING CT_FORMAT_API char * colour_text(format_context_t context, colour_t idx, const char *text)
add colour to a string
Definition: colour.c:56
@ eColourDefault
Definition: colour.h:32
@ eColourMagenta
Definition: colour.h:28
@ eColourCount
Definition: colour.h:34
@ eColourYellow
Definition: colour.h:26
@ eColourGreen
Definition: colour.h:25
@ eColourWhite
Definition: colour.h:30
@ eColourBlue
Definition: colour.h:27
@ eColourRed
Definition: colour.h:24
@ eColourCyan
Definition: colour.h:29
#define CT_BEGIN_API
Definition: compiler.h:129
#define CT_END_API
Definition: compiler.h:130
an allocator object
Definition: arena.h:86
a colour pallete
Definition: colour.h:39
const char * colours[eColourCount]
Definition: colour.h:40
STA_FIELD_STRING const char * reset
Definition: colour.h:41
a formatting context when using colours
Definition: colour.h:46
arena_t * arena
Definition: colour.h:47
const colour_pallete_t * pallete
Definition: colour.h:48