Added kernel log ui app

This commit is contained in:
Djeeberjr 2023-03-20 01:15:22 +01:00
parent 84d437104d
commit 204e464b1b

65
src/bin/KernelLog.hx Normal file
View File

@ -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<Bool> {
this.ctx = context;
Log.instance.onLog.handle(()->{
render();
});
render();
return new Future<Bool>(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);
}
}
}