There's some optimizations that I can do to reduce the color codes output. (FUTURE TODO).
@@ -34,12 +34,9 @@ void ansi_color(struct console_details *cdp, int color) {
cdp->bgcolor = 0;
return;
}
- if (color == 1) {
- cdp->status = 1;
- return;
- }
- if (color == 5) {
- cdp->status = 5;
+ if ((color == 1) || (color == 2) || (color == 3) || (color == 4) ||
+ (color == 5)) {
+ cdp->status = color;
if ((color >= 30) && (color <= 37)) {
@@ -67,6 +64,9 @@ const char *color_restore(struct console_details *cdp) {
static char buffer[30];
int slen;
+ // possible optimize: If fg is 7, don't set (0 reset does that), if bg is 0,
+ // don't set (0 does that)
+
if (cdp->status == 0) {
slen = snprintf(buffer, sizeof(buffer), "\x1b[0;3%d;4%dm", cdp->fgcolor,
cdp->bgcolor);