diff --git a/source/gogga/context.d b/source/gogga/context.d new file mode 100644 index 0000000..09d9f27 --- /dev/null +++ b/source/gogga/context.d @@ -0,0 +1,8 @@ +module gogga.context; + +import dlog; + +public final class GoggaContext : Context +{ + // TODO: Put more advanced stuff here +} \ No newline at end of file diff --git a/source/gogga/core.d b/source/gogga/core.d index 5388f19..268a19b 100644 --- a/source/gogga/core.d +++ b/source/gogga/core.d @@ -1,16 +1,11 @@ module gogga.core; -import std.conv : to; -import std.stdio : write, stdout; - -// TODO: Remove (just for testing) -import std.stdio : writeln; - import dlog; import dlog.utilities : flatten; import std.array : join; - +import gogga.transform; +import gogga.context; unittest { @@ -25,11 +20,6 @@ unittest // TODO: Add debug stuff } -public final class GoggaContext : Context -{ - // TODO: Put more advanced stuff here -} - public class GoggaLogger : Logger { private GoggaTransform gTransform = new GoggaTransform(); @@ -233,86 +223,4 @@ public class GoggaLogger : Logger { this.debugEnabled = false; } -} - -public class GoggaTransform : MessageTransform -{ - private bool isSourceMode = false; - - public override string transform(string text, Context ctx) - { - /* Get the GoggaContext */ - GoggaContext gCtx = cast(GoggaContext)ctx; - - /* Extract the line information */ - CompilationInfo compInfo = gCtx.getLineInfo(); - string[] context = compInfo.toArray(); - - /* Module information (and status debugColoring) */ - string moduleInfo = cast(string)debugColor("["~context[1]~"]", gCtx.getLevel()); - - /* Function and line number info */ - string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")")); - - return moduleInfo~" "~funcInfo~" "~text~"\n"; - } -} - -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 WARNING, set warning */ - else if(level == Level.WARN) - { - messageBytes = cast(byte[])[27, '[','3','5','m']; /* TODO: FInd yllow */ - } - /* If ERROR, set error */ - else if(level == Level.ERROR) - { - messageBytes = cast(byte[])[27, '[','3','1','m']; - } - - /* Add the message */ - messageBytes ~= cast(byte[])text; - - /* Switch back debugColor */ - messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm']; - - return messageBytes; -} - -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; -} - -unittest -{ - // alias debugTypes = __traits(allMembers, DebugType); - // static foreach(debugType; debugTypes) - // { - // gprintln("Hello world", mixin("DebugType."~debugType)); - // } } \ No newline at end of file diff --git a/source/gogga/transform.d b/source/gogga/transform.d new file mode 100644 index 0000000..0543173 --- /dev/null +++ b/source/gogga/transform.d @@ -0,0 +1,77 @@ +module gogga.transform; + +import dlog; +import gogga.context; + +public class GoggaTransform : MessageTransform +{ + private bool isSourceMode = false; + + public override string transform(string text, Context ctx) + { + /* Get the GoggaContext */ + GoggaContext gCtx = cast(GoggaContext)ctx; + + /* Extract the line information */ + CompilationInfo compInfo = gCtx.getLineInfo(); + string[] context = compInfo.toArray(); + + /* Module information (and status debugColoring) */ + string moduleInfo = cast(string)debugColor("["~context[1]~"]", gCtx.getLevel()); + + /* Function and line number info */ + string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")")); + + return moduleInfo~" "~funcInfo~" "~text~"\n"; + } +} + +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 WARNING, set warning */ + else if(level == Level.WARN) + { + messageBytes = cast(byte[])[27, '[','3','5','m']; /* TODO: FInd yllow */ + } + /* If ERROR, set error */ + else if(level == Level.ERROR) + { + messageBytes = cast(byte[])[27, '[','3','1','m']; + } + + /* Add the message */ + messageBytes ~= cast(byte[])text; + + /* Switch back debugColor */ + messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm']; + + return messageBytes; +} + +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