1 module gogga; 2 3 import std.conv : to; 4 import std.stdio : write, stdout; 5 6 public enum DebugType 7 { 8 INFO, 9 WARNING, 10 ERROR 11 } 12 13 byte[] generateMessage(string message, DebugType debugType) 14 { 15 /* The generated message */ 16 byte[] messageBytes; 17 18 /* If INFO, set green */ 19 if(debugType == DebugType.INFO) 20 { 21 messageBytes = cast(byte[])[27, '[','3','2','m']; 22 } 23 /* If WARNING, set warning */ 24 else if(debugType == DebugType.WARNING) 25 { 26 messageBytes = cast(byte[])[27, '[','3','5','m']; /* TODO: FInd yllow */ 27 } 28 /* If ERROR, set error */ 29 else if(debugType == DebugType.ERROR) 30 { 31 messageBytes = cast(byte[])[27, '[','3','1','m']; 32 } 33 34 /* Write the message type */ 35 messageBytes ~= "["~to!(string)(debugType)~"] "; 36 37 /* Switch back color */ 38 messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm']; 39 40 return messageBytes; 41 } 42 43 void gprint(messageT)(messageT message, DebugType debugType = DebugType.INFO) 44 { 45 /* Generate the message */ 46 byte[] messageBytes = generateMessage(message, debugType); 47 48 /* Print the message */ 49 write(messageBytes); 50 } 51 52 void gprintln(messageT)(messageT message, DebugType debugType = DebugType.INFO) 53 { 54 /* Generate the string to print */ 55 string printStr = to!(string)(message)~"\n"; 56 57 /* Call `gprint` */ 58 gprint(printStr, debugType); 59 }