From 93ada2077b8c66afd9325a738ddfcea67c2c7cbf Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:33:31 -0400 Subject: [PATCH] Change color functions --- source/birchwood/protocol/formatting.d | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index b0081a9..eeca25b 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -49,11 +49,30 @@ char generate_color_control_char(string color) { } } -// Generate a string that sets the foreground color -string set_fg(string color) {return [generate_color_control_char(color)] ~ color;} +// Generates a string that changes the foreground color +string set_foreground(string color) { + char[1] control_char; + if (color.length == 6) { + control_char[0] = hex_color_code; + } else if (color.length == 2) { + control_char[0] = ascii_color_code; + } else { + throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)"); + } + return control_char ~ color; // Generate a string that sets the foreground and background color -string set_fg_bg(string color) {return [generate_color_control_char(color)] ~ color ~ "," ~ color;} +string set_foreground_background(string fg, string bg) { + char[1] control_char; + if (color.length == 6) { + control_char[0] = hex_color_code; + } else if (color.length == 2) { + control_char[0] = ascii_color_code; + } else { + throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)"); + } + return control_char ~ fg ~ "," ~ bg; +} // Generate a string that resets the foreground and background colors pragma(inline)