diff --git a/source/app.d b/source/app.d new file mode 100644 index 0000000..959c4c6 --- /dev/null +++ b/source/app.d @@ -0,0 +1,8 @@ +module app; + +import gogga; + +void main() +{ + gprint("Hello poes"); +} \ No newline at end of file diff --git a/source/gogga.d b/source/gogga.d new file mode 100644 index 0000000..922014f --- /dev/null +++ b/source/gogga.d @@ -0,0 +1,66 @@ +module gogga; + +import std.conv : to; +import std.stdio : write, stdout; +import core.sync.mutex : Mutex; + +public enum DebugType +{ + INFO, + WARNING, + ERROR +} + +private __gshared Mutex writeMutex; + +/* Initialize the module (only once, regardless of threads) */ +shared static this() +{ + /* Initialize the mutex */ + writeMutex = new Mutex(); +} + +void gprint(messageT)(messageT message, DebugType debugType = DebugType.INFO) +{ + /* TODO: Remove mutex, oneshot write */ + + /* Lock output */ + writeMutex.lock(); + + /* If INFO, set green */ + if(debugType == DebugType.INFO) + { + stdout.rawWrite(cast(byte[])[27, '[','3','2','m']); + } + /* If WARNING, set warning */ + else if(debugType == DebugType.WARNING) + { + stdout.rawWrite(cast(byte[])[27, '[','3','5','m']); /* TODO: FInd yllow */ + } + /* If ERROR, set error */ + else if(debugType == DebugType.ERROR) + { + stdout.rawWrite(cast(byte[])[27, '[','3','1','m']); + } + + /* Write the message type */ + write("["~to!(string)(debugType)~"] "); + + /* Switch back color */ + stdout.rawWrite(cast(byte[])[27, '[', '3', '9', 'm']); + + /* Print the message */ + write(message); + + /* Unlock output */ + writeMutex.lock(); +} + +void gprintln(messageT)(messageT message, DebugType debugType = DebugType.INFO) +{ + /* Generate the string to print */ + string printStr = to!(string)(message)~"\n"; + + /* Call `gprint` */ + gprint(printStr, debugType); +} \ No newline at end of file