diff --git a/src/bin/KernelLog.hx b/src/bin/KernelLog.hx new file mode 100644 index 0000000..50b6f2c --- /dev/null +++ b/src/bin/KernelLog.hx @@ -0,0 +1,65 @@ +package bin; + +import lib.Color; +import lib.MathI; +import kernel.log.Log; +import kernel.ui.WindowContext; +import lib.ui.UIApp; + +using tink.CoreApi; + +class KernelLog extends UIApp{ + private var ctx:WindowContext; + private var exitTrigger: Bool -> Void; + + public function new() {} + + public function invoke(context:WindowContext):Future { + this.ctx = context; + + Log.instance.onLog.handle(()->{ + render(); + }); + + render(); + + return new Future(cb -> { + this.exitTrigger = cb; + return null; + }); + } + + private function render() { + ctx.clear(); + ctx.setCursorPos(0,0); + + var lines = Log.instance.getLines(); + var height = ctx.getSize().y; + var start = MathI.max(lines.length - height,0); + + for (i in start...lines.length) { + var line = lines[i]; + + switch (line.level){ + case Info: + ctx.setTextColor(Color.White); + ctx.write("[INFO] "); + case Warn: + ctx.setTextColor(Color.Yellow); + ctx.write("[WARN] "); + case Error: + ctx.setTextColor(Color.Red); + ctx.write("[ERRO] "); + case Debug: + ctx.setTextColor(Color.Gray); + ctx.write("[DEBG] "); + case Silly: + ctx.setTextColor(Color.Gray); + ctx.write("[SILL] "); + } + + ctx.write(line.message); + ctx.setCursorPos(0,ctx.getCursorPos().y + 1); + } + } +}