- Adding transform modes

This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-02 13:44:10 +02:00
parent 7652938043
commit 7ad503825f
1 changed files with 47 additions and 7 deletions

View File

@ -3,12 +3,24 @@ module gogga.transform;
import dlog;
import gogga.context;
// TODO: hehe easter egg TRADITIONAL, LIBERAL, UNHINGED
public enum GoggaMode
{
SIMPLE,
TwoKTwenty3,
RUSTACEAN
}
public class GoggaTransform : MessageTransform
{
private bool isSourceMode = false;
private GoggaMode mode;
public override string transform(string text, Context ctx)
{
/* The generated output string */
string finalOutput;
/* Get the GoggaContext */
GoggaContext gCtx = cast(GoggaContext)ctx;
@ -16,13 +28,41 @@ public class GoggaTransform : MessageTransform
CompilationInfo compInfo = gCtx.getLineInfo();
string[] context = compInfo.toArray();
/* Extract the Level */
Level level = gCtx.getLevel();
// TODO: go for [<LEVEL>] (<filePath>/<functionName>:<lineNumber>) <message>
/**
* Simple mode is just: `[<LEVEL>] <message>`
*/
if(mode == GoggaMode.SIMPLE)
{
finalOutput = cast(string)debugColor("["~to!(string)(level)~"] "~text);
}
/**
* TwoKTwenty3 is: `[<file>] (<module>:<lineNumber>) <message>`
*/
else if(mode == Gogga.TwoKTwenty3)
{
/* Module information (and status debugColoring) */
string moduleInfo = cast(string)debugColor("["~context[1]~"]", gCtx.getLevel());
string moduleInfo = cast(string)debugColor("["~context[1]~"]", level);
/* Function and line number info */
string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")"));
return moduleInfo~" "~funcInfo~" "~text~"\n";
finalOutput = moduleInfo~" "~funcInfo~" "~text~"\n";
}
/**
* Rustacean mode
*/
else
{
}
return finalOutput;
}
}