From 208cfebf49f8e210a115bc320af11fd4d7663b2b Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 19 Mar 2023 11:58:44 +0200 Subject: [PATCH] Formatting - Added TODO for import `std.string` - Added documentation to `SimpleColor` enum - Added documentation and code-styled `reset_fg_bg()`, `bold(string)`, `italics(string)`, `underline(string)`, `strikethrough(string)` and `monospace(string)` --- source/birchwood/protocol/formatting.d | 90 +++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/source/birchwood/protocol/formatting.d b/source/birchwood/protocol/formatting.d index 0c82870..a4c415a 100644 --- a/source/birchwood/protocol/formatting.d +++ b/source/birchwood/protocol/formatting.d @@ -3,6 +3,7 @@ */ module birchwood.protocol.formatting; +// FIXME: Remove below import and start using BirchwoodException import std.string; // Reset character; resets all formatting @@ -20,8 +21,10 @@ enum reverse_colors_code = '\x16'; // NOT UNIVERSALLY SUPPORTED enum ascii_color_code = '\x03'; enum hex_color_code = '\x04'; -// Simple color codes -enum SimpleColor: string { +/** + * Simple color codes + */ +public enum SimpleColor: string { WHITE = "00", BLACK = "01", BLUE = "02", @@ -94,22 +97,89 @@ string set_foreground_background(SimpleColor fg, SimpleColor bg) { return ascii_color_code ~ fg ~ "," ~ bg; } -// Generate a string that resets the foreground and background colors +/** + * Generate a string that resets the foreground + * and background colors + * + * Returns: The control string + */ pragma(inline) -string reset_fg_bg() {return [ascii_color_code].idup;} +string reset_fg_bg() +{ + return [ascii_color_code].idup; +} + + + // Format strings with functions -pragma(inline) -string bold(string text) {return bold_code~text~bold_code;} +/** + * Formats the provided text as bold + * + * Params: + * text = the text to bolden + * + * Returns: the boldened text + */ pragma(inline) -string italics(string text) {return italic_code~text~italic_code;} +string bold(string text) +{ + return bold_code~text~bold_code; +} +/** + * Formats the provided text in italics + * + * Params: + * text = the text to italicize + * + * Returns: the italicized text + */ pragma(inline) -string underline(string text) {return underline_code~text~underline_code;} +string italics(string text) +{ + return italic_code~text~italic_code; +} +/** + * Formats the text as underlined + * + * Params: + * text = the text to underline + * + * Returns: the underlined text + */ pragma(inline) -string strikethrough(string text) {return strikethrough_code~text~strikethrough_code;} +string underline(string text) +{ + return underline_code~text~underline_code; +} +/** + * Formats the text as strikethroughed + * + * Params: + * text = the text to strikethrough + * + * Returns: the strikethroughed text + */ pragma(inline) -string monospace(string text) {return monospace_code~text~monospace_code;} \ No newline at end of file +string strikethrough(string text) +{ + return strikethrough_code~text~strikethrough_code; +} + +/** + * Formats the text as monospaced + * + * Params: + * text = the text to monospace + * + * Returns: the monospaced text + */ +pragma(inline) +string monospace(string text) +{ + return monospace_code~text~monospace_code; +} \ No newline at end of file