From 8c8c226742ef8fd3aa729965c6258994d556b752 Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:46:39 -0400 Subject: [PATCH 01/10] Create formatting.d --- source/birchwood/formatting.d | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 source/birchwood/formatting.d diff --git a/source/birchwood/formatting.d b/source/birchwood/formatting.d new file mode 100644 index 0000000..975da7f --- /dev/null +++ b/source/birchwood/formatting.d @@ -0,0 +1,48 @@ +module birchwood.formatting + +import std.string; + +// Toggle characters +enum bold = '\x02'; +enum italic = '\x1D'; +enum underline = '\x1F'; +enum strikethrough = '\x1E'; +enum monospace = '\x11'; + +// Color characters +enum ascii_color_code = '\x03'; +enum hex_color_code = '\x04'; + +// Simple color codes +enum simple_colors: string { + WHITE = "00", + BLACK = "01", + BLUE = "02", + GREEN = "03", + RED = "04", + BROWN = "05", + MAGENTA = "06", + ORANGE = "07", + YELLOW = "08", + LIGHT_GREEN = "09", + CYAN = "10", + LIGHT_CYAN = "11", + LIGHT_BLUE = "12", + PINK = "13", + GREY = "14", + LIGHT_GREY = "15", + DEFAULT = "99" // NOT UNIVERSALLY SUPPORTED +} + +// 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.idup ~ color; +} \ No newline at end of file From dcf32b2a136d174266156ac6f8f08d5df7fe33a5 Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:47:01 -0400 Subject: [PATCH 02/10] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed07c15..cb507eb 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Birchwood dependends on the following D libraries: You can take a look at the `Client` API documentation on [DUB](https://birchwood.dpldocs.info/birchwood.client.Client.html). -## Compatibiloty +## Compatibility - [ ] rfc1459 * Should be more or less stable in supporting this standard From 464773daa8125a30206f244955d6fb1e1a4144fb Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:58:49 -0400 Subject: [PATCH 03/10] Edit colors and add more control codes --- source/birchwood/formatting.d | 26 +++++++++++++++++++------- source/birchwood/package.d | 3 ++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/source/birchwood/formatting.d b/source/birchwood/formatting.d index 975da7f..2fbbc39 100644 --- a/source/birchwood/formatting.d +++ b/source/birchwood/formatting.d @@ -2,12 +2,16 @@ module birchwood.formatting import std.string; +// Reset character; resets all formatting +enum reset = '\x0F'; + // Toggle characters enum bold = '\x02'; enum italic = '\x1D'; enum underline = '\x1F'; enum strikethrough = '\x1E'; enum monospace = '\x11'; +enum reverse_colors = '\x16'; // NOT UNIVERSALLY SUPPORTED // Color characters enum ascii_color_code = '\x03'; @@ -34,15 +38,23 @@ enum simple_colors: string { DEFAULT = "99" // NOT UNIVERSALLY SUPPORTED } -// Generates a string that changes the foreground color -string set_foreground(string color) { - char[1] control_char; +// Return the hex control character if color is a hexadecimal color code, the ASCII control character if color is two ASCII digits, and throw an exception if it's neither +char generate_color_control_char(string color) { if (color.length == 6) { - control_char[0] = hex_color_code; + return hex_color_code; } else if (color.length == 2) { - control_char[0] = ascii_color_code; + return 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.idup ~ color; -} \ No newline at end of file +} + +// Generate a string that sets the foreground color +string set_fg(string color) {return [generate_color_control_char(color)].idup ~ color;} + +// Generate a string that sets the foreground and background color +string set_fg_bg(string color) {return [generate_color_control_char(color)].idup ~ color ~ "," ~ color;} + +// Generate a string that resets the foreground and background colors +pragma(inline) +string reset_fg_bg() {return "\x03";} \ No newline at end of file diff --git a/source/birchwood/package.d b/source/birchwood/package.d index d9018f1..b98ed1d 100644 --- a/source/birchwood/package.d +++ b/source/birchwood/package.d @@ -2,4 +2,5 @@ module birchwood; public import birchwood.client; public import birchwood.config; -public import birchwood.protocol; \ No newline at end of file +public import birchwood.protocol; +public import birchwood.formatting \ No newline at end of file From 7198a2dec6fe4ff31f5ce87d79742ddc0bbe25ce Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:03:38 -0400 Subject: [PATCH 04/10] Add missing semicolons --- source/birchwood/formatting.d | 2 +- source/birchwood/package.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/birchwood/formatting.d b/source/birchwood/formatting.d index 2fbbc39..47facd4 100644 --- a/source/birchwood/formatting.d +++ b/source/birchwood/formatting.d @@ -1,4 +1,4 @@ -module birchwood.formatting +module birchwood.formatting; import std.string; diff --git a/source/birchwood/package.d b/source/birchwood/package.d index b98ed1d..1ae36e1 100644 --- a/source/birchwood/package.d +++ b/source/birchwood/package.d @@ -3,4 +3,4 @@ module birchwood; public import birchwood.client; public import birchwood.config; public import birchwood.protocol; -public import birchwood.formatting \ No newline at end of file +public import birchwood.formatting; \ No newline at end of file From 937494bfb06cba059780d528e7844946d0a5820d Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:26:12 -0400 Subject: [PATCH 05/10] Move formatting.d and add formatting functions --- source/birchwood/formatting.d | 60 --------------------- source/birchwood/package.d | 3 +- source/birchwood/protocol/formatting.d | 74 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 62 deletions(-) delete mode 100644 source/birchwood/formatting.d diff --git a/source/birchwood/formatting.d b/source/birchwood/formatting.d deleted file mode 100644 index 47facd4..0000000 --- a/source/birchwood/formatting.d +++ /dev/null @@ -1,60 +0,0 @@ -module birchwood.formatting; - -import std.string; - -// Reset character; resets all formatting -enum reset = '\x0F'; - -// Toggle characters -enum bold = '\x02'; -enum italic = '\x1D'; -enum underline = '\x1F'; -enum strikethrough = '\x1E'; -enum monospace = '\x11'; -enum reverse_colors = '\x16'; // NOT UNIVERSALLY SUPPORTED - -// Color characters -enum ascii_color_code = '\x03'; -enum hex_color_code = '\x04'; - -// Simple color codes -enum simple_colors: string { - WHITE = "00", - BLACK = "01", - BLUE = "02", - GREEN = "03", - RED = "04", - BROWN = "05", - MAGENTA = "06", - ORANGE = "07", - YELLOW = "08", - LIGHT_GREEN = "09", - CYAN = "10", - LIGHT_CYAN = "11", - LIGHT_BLUE = "12", - PINK = "13", - GREY = "14", - LIGHT_GREY = "15", - DEFAULT = "99" // NOT UNIVERSALLY SUPPORTED -} - -// Return the hex control character if color is a hexadecimal color code, the ASCII control character if color is two ASCII digits, and throw an exception if it's neither -char generate_color_control_char(string color) { - if (color.length == 6) { - return hex_color_code; - } else if (color.length == 2) { - return ascii_color_code; - } else { - throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)"); - } -} - -// Generate a string that sets the foreground color -string set_fg(string color) {return [generate_color_control_char(color)].idup ~ color;} - -// Generate a string that sets the foreground and background color -string set_fg_bg(string color) {return [generate_color_control_char(color)].idup ~ color ~ "," ~ color;} - -// Generate a string that resets the foreground and background colors -pragma(inline) -string reset_fg_bg() {return "\x03";} \ No newline at end of file diff --git a/source/birchwood/package.d b/source/birchwood/package.d index 1ae36e1..d9018f1 100644 --- a/source/birchwood/package.d +++ b/source/birchwood/package.d @@ -2,5 +2,4 @@ module birchwood; public import birchwood.client; public import birchwood.config; -public import birchwood.protocol; -public import birchwood.formatting; \ No newline at end of file +public import birchwood.protocol; \ No newline at end of file diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index b0abaff..b0081a9 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -1,2 +1,76 @@ module birchwood.protocol.formatting; +import std.string; + +// Reset character; resets all formatting +enum reset = '\x0F'; + +// Toggle characters +enum bold_code = '\x02'; +enum italic_code = '\x1D'; +enum underline_code = '\x1F'; +enum strikethrough_code = '\x1E'; +enum monospace_code = '\x11'; +enum reverse_colors_code = '\x16'; // NOT UNIVERSALLY SUPPORTED + +// Color characters +enum ascii_color_code = '\x03'; +enum hex_color_code = '\x04'; + +// Simple color codes +enum simple_colors: string { + WHITE = "00", + BLACK = "01", + BLUE = "02", + GREEN = "03", + RED = "04", + BROWN = "05", + MAGENTA = "06", + ORANGE = "07", + YELLOW = "08", + LIGHT_GREEN = "09", + CYAN = "10", + LIGHT_CYAN = "11", + LIGHT_BLUE = "12", + PINK = "13", + GREY = "14", + LIGHT_GREY = "15", + DEFAULT = "99" // NOT UNIVERSALLY SUPPORTED +} + +// Return the hex control character if color is a hexadecimal color code, the ASCII control character if color is two ASCII digits, and throw an exception if it's neither +char generate_color_control_char(string color) { + if (color.length == 6) { + return hex_color_code; + } else if (color.length == 2) { + return ascii_color_code; + } else { + throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)"); + } +} + +// Generate a string that sets the foreground color +string set_fg(string color) {return [generate_color_control_char(color)] ~ 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;} + +// Generate a string that resets the foreground and background colors +pragma(inline) +string reset_fg_bg() {return "\x03";} + +// Format strings with functions +pragma(inline) +string bold(string text) {return bold_code~text~bold_code;} + +pragma(inline) +string italics(string text) {return italic_code~text~italic_code;} + +pragma(inline) +string underline(string text) {return underline_code~text~underline_code;} + +pragma(inline) +string strikethrough(string text) {return strikethrough_code~text~strikethrough_code;} + +pragma(inline) +string monospace(string text) {return monospace_code~text~monospace_code;} \ No newline at end of file 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 06/10] 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) From 1fe990ac3635528929014262d71c0d74a4d0f639 Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:43:10 -0400 Subject: [PATCH 07/10] Minor edits --- source/birchwood/protocol/formatting.d | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index eeca25b..74fc274 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -3,7 +3,7 @@ module birchwood.protocol.formatting; import std.string; // Reset character; resets all formatting -enum reset = '\x0F'; +enum reset_code = '\x0F'; // Toggle characters enum bold_code = '\x02'; @@ -39,6 +39,7 @@ enum simple_colors: string { } // Return the hex control character if color is a hexadecimal color code, the ASCII control character if color is two ASCII digits, and throw an exception if it's neither +// This function might be useless now that set_fg and set_fg_bg have been changed, but I'll keep it in case it's needed later. char generate_color_control_char(string color) { if (color.length == 6) { return hex_color_code; @@ -64,9 +65,12 @@ string set_foreground(string color) { // Generate a string that sets the foreground and background color string set_foreground_background(string fg, string bg) { char[1] control_char; - if (color.length == 6) { + if (fg.length != bg.length) { + throw new StringException("Invalid color code (cannot mix hex and ASCII)"); + } + if (fg.length == 6) { control_char[0] = hex_color_code; - } else if (color.length == 2) { + } else if (fg.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)"); @@ -76,7 +80,7 @@ string set_foreground_background(string fg, string bg) { // Generate a string that resets the foreground and background colors pragma(inline) -string reset_fg_bg() {return "\x03";} +string reset_fg_bg() {return ascii_color_code;} // Format strings with functions pragma(inline) From a4b75a322d849188334010fbfbf9ca952f5bc42b Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Fri, 17 Mar 2023 10:34:56 -0400 Subject: [PATCH 08/10] Add simpleColor function overloads --- source/birchwood/protocol/formatting.d | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index 74fc274..9f34f91 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -18,7 +18,7 @@ enum ascii_color_code = '\x03'; enum hex_color_code = '\x04'; // Simple color codes -enum simple_colors: string { +enum simpleColor: string { WHITE = "00", BLACK = "01", BLUE = "02", @@ -78,6 +78,18 @@ string set_foreground_background(string fg, string bg) { return control_char ~ fg ~ "," ~ bg; } +// Generates a string that changes the foreground color (except enum) +pragma(inline) +string set_foreground(simpleColor color) { + return ascii_color_code ~ color; +} + +// Generate a string that sets the foreground and background color (except enum) +pragma(inline) +string set_foreground_background(simpleColor fg, simpleColor bg) { + return ascii_color_code ~ fg ~ "," ~ bg; +} + // Generate a string that resets the foreground and background colors pragma(inline) string reset_fg_bg() {return ascii_color_code;} From 5c377e0572a7014d945fc4beb82a97bf364b0923 Mon Sep 17 00:00:00 2001 From: supremestdoggo <83146042+supremestdoggo@users.noreply.github.com> Date: Fri, 17 Mar 2023 10:40:18 -0400 Subject: [PATCH 09/10] Fix build errors --- source/birchwood/protocol/formatting.d | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index 9f34f91..a3fb7b7 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -60,7 +60,8 @@ string set_foreground(string color) { } 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; + return control_char.idup ~ color; +} // Generate a string that sets the foreground and background color string set_foreground_background(string fg, string bg) { @@ -75,7 +76,7 @@ string set_foreground_background(string fg, string bg) { } 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; + return control_char.idup ~ fg ~ "," ~ bg; } // Generates a string that changes the foreground color (except enum) @@ -92,7 +93,7 @@ string set_foreground_background(simpleColor fg, simpleColor bg) { // Generate a string that resets the foreground and background colors pragma(inline) -string reset_fg_bg() {return ascii_color_code;} +string reset_fg_bg() {return [ascii_color_code].idup;} // Format strings with functions pragma(inline) From fd1f204f91e3595539a67c74f38d0c75c20ed4cb Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 13:04:08 +0200 Subject: [PATCH 10/10] README - Typo fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0aa557..d2dd262 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ dub add birchwood ### Dependencies -Birchwood dependends on the following D libraries: +Birchwood depends on the following D libraries: * `libsnooze` (0.3.0) * `eventy` (0.4.0)