Extremely minimal color printing utilities for C++.
1#include "colors.hpp"
2#include <string>
3
4namespace colors {
5 func black(std::string str) noexcept -> std::string {
6 auto const prefix = "\033[30m";
7 auto const suffix = "\033[0m";
8 return prefix + str + suffix;
9 }
10
11 func red(std::string str) noexcept -> std::string {
12 auto const prefix = "\033[31m";
13 auto const suffix = "\033[0m";
14 return prefix + str + suffix;
15 }
16
17 func green(std::string str) noexcept -> std::string {
18 auto const prefix = "\033[32m";
19 auto const suffix = "\033[0m";
20 return prefix + str + suffix;
21 }
22
23 func yellow(std::string str) noexcept -> std::string {
24 auto const prefix = "\033[33m";
25 auto const suffix = "\033[0m";
26 return prefix + str + suffix;
27 }
28
29 func blue(std::string str) noexcept -> std::string {
30 auto const prefix = "\033[34m";
31 auto const suffix = "\033[0m";
32 return prefix + str + suffix;
33 }
34
35 func magenta(std::string str) noexcept -> std::string {
36 auto const prefix = "\033[35m";
37 auto const suffix = "\033[0m";
38 return prefix + str + suffix;
39 }
40
41 func cyan(std::string str) noexcept -> std::string {
42 auto const prefix = "\033[36m";
43 auto const suffix = "\033[0m";
44 return prefix + str + suffix;
45 }
46
47 func bold(std::string str) noexcept -> std::string {
48 auto const prefix = "\033[1m";
49 auto const suffix = "\033[0m";
50 return prefix + str + suffix;
51 }
52
53 func underline(std::string str) noexcept -> std::string {
54 auto const prefix = "\033[4m";
55 auto const suffix = "\033[0m";
56 return prefix + str + suffix;
57 }
58
59 func italic(std::string str) noexcept -> std::string {
60 auto const prefix = "\033[3m";
61 auto const suffix = "\033[0m";
62 return prefix + str + suffix;
63 }
64
65 func faint(std::string str) noexcept -> std::string {
66 auto const prefix = "\033[2m";
67 auto const suffix = "\033[0m";
68 return prefix + str + suffix;
69 }
70
71 func blink(std::string str) noexcept -> std::string {
72 auto const prefix = "\033[5m";
73 auto const suffix = "\033[0m";
74 return prefix + str + suffix;
75 }
76}