From 861f4bc8d3884ed7e9e9317a13a174ad82bb5fbb Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 9 Apr 2024 14:34:26 +0200 Subject: [PATCH] Context - Removed Transform - Removed --- source/gogga/context.d | 14 --- source/gogga/transform.d | 201 --------------------------------------- 2 files changed, 215 deletions(-) delete mode 100644 source/gogga/context.d delete mode 100644 source/gogga/transform.d diff --git a/source/gogga/context.d b/source/gogga/context.d deleted file mode 100644 index 4b4f6d1..0000000 --- a/source/gogga/context.d +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Custom context for gogga logging - */ -module gogga.context; - -import dlog; - -/** - * Pass in a custom context to be used for gogga - */ -public final class GoggaContext : Context -{ - // TODO: Put more advanced stuff here -} \ No newline at end of file diff --git a/source/gogga/transform.d b/source/gogga/transform.d deleted file mode 100644 index a744d75..0000000 --- a/source/gogga/transform.d +++ /dev/null @@ -1,201 +0,0 @@ -/** - * The custom text transformer that implements the gogga-stylised - * logging messages - */ -module gogga.transform; - -import dlog; -import gogga.context; -import std.conv : to; - -/** - * The gogga styles supported - */ -public enum GoggaMode -{ - /** - * TwoKTwenty3 is: `[] (:) ` - */ - TwoKTwenty3, - - /** - * Simple mode is just: `[] ` - */ - SIMPLE, - - /** - * Rustacean mode is: `[] (/:) ` - */ - RUSTACEAN, - - /** - * Simple rustacean mode is: `[] (:) ` - */ - RUSTACEAN_SIMPLE -} - -/** - * The custom gogga text transformer - */ -public class GoggaTransform : MessageTransform -{ - /** - * Current style - */ - private GoggaMode mode; - - /** - * Transforms the provided text - * - * Params: - * text = text to transform - * ctx = the context passed in - * Returns: a string of transformed text - */ - public override string transform(string text, Context ctx) - { - /* The generated output string */ - string finalOutput; - - - /* Get the GoggaContext */ - GoggaContext gCtx = cast(GoggaContext)ctx; - - /* Extract the line information */ - CompilationInfo compInfo = gCtx.getLineInfo(); - string[] context = compInfo.toArray(); - - /* Extract the Level */ - Level level = gCtx.getLevel(); - - - /** - * Simple mode is just: `[] ` - */ - if(mode == GoggaMode.SIMPLE) - { - finalOutput = cast(string)debugColor("["~to!(string)(level)~"] ", level); - - finalOutput ~= text~"\n"; - } - /** - * TwoKTwenty3 is: `[] (:) ` - */ - else if(mode == GoggaMode.TwoKTwenty3) - { - /* Module information (and status debugColoring) */ - string moduleInfo = cast(string)debugColor("["~context[1]~"]", level); - - /* Function and line number info */ - string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")")); - - finalOutput = moduleInfo~" "~funcInfo~" "~text~"\n"; - } - /** - * Rustacean mode is: `[] (/:) ` - */ - else if(mode == GoggaMode.RUSTACEAN) - { - finalOutput = cast(string)debugColor(to!(string)(level)~"\t", level); - finalOutput ~= cast(string)(colorSrc(context[1]~"/"~context[4]~":"~context[2]~" ")); - finalOutput ~= text~"\n"; - } - /** - * Simple rustacean mode is: `[] (:) ` - */ - else if(mode == GoggaMode.RUSTACEAN_SIMPLE) - { - finalOutput = cast(string)debugColor(to!(string)(level)~"\t", level); - finalOutput ~= cast(string)(colorSrc(context[4]~":"~context[2]~" ")); - finalOutput ~= text~"\n"; - } - - return finalOutput; - } - - /** - * Set the gogga style - * - * Params: - * mode = the GoggaMode to use - */ - public void setMode(GoggaMode mode) - { - this.mode = mode; - } -} - -/** - * Colorise the text provided accoridng to the level and then - * reset the colors at the end - * - * Params: - * text = the text to colorise - * level = the color to use - * Returns: the byte sequence of characters and controls - */ -private byte[] debugColor(string text, Level level) -{ - /* The generated message */ - byte[] messageBytes; - - /* If INFO, set green */ - if(level == Level.INFO) - { - messageBytes = cast(byte[])[27, '[','3','2','m']; - } - /* If WARN, set yellow */ - else if(level == Level.WARN) - { - messageBytes = cast(byte[])[27, '[','3','1', ';', '9', '3', 'm']; - } - /* If ERROR, set red */ - else if(level == Level.ERROR) - { - messageBytes = cast(byte[])[27, '[','3','1','m']; - } - /* If DEBUG, set pink */ - else - { - messageBytes = cast(byte[])[27, '[','3','5','m']; - } - - /* Add the message */ - messageBytes ~= cast(byte[])text; - - /* Switch back debugColor */ - messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm']; - - /* Reset coloring */ - messageBytes ~= [27, '[', 'm']; - - return messageBytes; -} - -/** - * Colors the provided text in a gray fashion and then - * resets back to normal - * - * Params: - * text = the text to gray color - * Returns: the byte sequence of characters and controls - */ -private byte[] colorSrc(string text) -{ - /* The generated message */ - byte[] messageBytes; - - /* Reset coloring */ - messageBytes ~= [27, '[', 'm']; - - /* Color gray */ - messageBytes ~= [27, '[', '3', '9', ';', '2', 'm']; - - /* Append the message */ - messageBytes ~= text; - - /* Reset coloring */ - messageBytes ~= [27, '[', 'm']; - - return messageBytes; -} \ No newline at end of file