-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.c
More file actions
38 lines (27 loc) · 744 Bytes
/
print.c
File metadata and controls
38 lines (27 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright: 2023 Jakub Korytko
#include "utils/print.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int is_coloring_enabled() {
char *enable_coloring = getenv("ENABLE_COLORING");
if (enable_coloring == NULL) {
return 1;
}
if (strcmp(enable_coloring, "false") == 0) {
return 0;
}
return 1;
}
void clear_stream(void) {
int c;
while ((c = getchar()) != '\n' && c != EOF) continue;
}
int color_printf(char *text, enum COLORS color) {
if (!is_coloring_enabled()) return printf("%s", text);
printf("\033[0;%dm%s\033[0m", color, text);
}
int num_printf(int number, enum COLORS color) {
if (!is_coloring_enabled()) return printf("%d", number);
printf("\033[0;%dm%d\033[0m", color, number);
}