From 8dca828cf3d69f37908f333a2f68a6ea612ecb6d Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Tue, 18 Apr 2023 19:57:12 +0200 Subject: [PATCH] use process on KernelLog --- src/bin/KernelLog.hx | 26 +++++++++++++------------- src/lib/HomeContext.hx | 18 +++++++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/bin/KernelLog.hx b/src/bin/KernelLog.hx index 50b6f2c..37b45d8 100644 --- a/src/bin/KernelLog.hx +++ b/src/bin/KernelLog.hx @@ -1,5 +1,7 @@ package bin; +import kernel.ps.ProcessHandle; +import kernel.ps.Process; import lib.Color; import lib.MathI; import kernel.log.Log; @@ -8,24 +10,22 @@ import lib.ui.UIApp; using tink.CoreApi; -class KernelLog extends UIApp{ - private var ctx:WindowContext; - private var exitTrigger: Bool -> Void; +class KernelLog implements Process { + private var handle: ProcessHandle; + private var ctx: WindowContext; public function new() {} - public function invoke(context:WindowContext):Future { - this.ctx = context; + public function run(handle: ProcessHandle):Void { + this.handle = handle; + + var statelessCtx = handle.createStatelessWindowContext(); + this.ctx = statelessCtx.ctx; + + statelessCtx.setRenderFunc(this.render); Log.instance.onLog.handle(()->{ - render(); - }); - - render(); - - return new Future(cb -> { - this.exitTrigger = cb; - return null; + statelessCtx.requestRender(); }); } diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index c6dee80..d9876a7 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -1,5 +1,6 @@ package lib; +import kernel.ps.ProcessManager; import bin.KernelLog; import lib.ui.elements.UIElement; import lib.ui.elements.TextElement; @@ -104,17 +105,20 @@ class HomeContext { private function addLog(){ - var newContext = WindowManager.instance.createNewBufferedContext(); + var pid = ProcessManager.run(new KernelLog(),{ - // Create new terminal - var term = new KernelLog(); - term.invoke(newContext); + }); - var contextID = addContextNextWorkspace(newContext); - if (contextID == -1) { + var lastContextID = -1; + + for ( ctx in WindowManager.instance.getContextByPID(pid)){ + lastContextID = addContextNextWorkspace(ctx); + } + + if (lastContextID == -1) { return; } - focusContext(contextID); + focusContext(lastContextID); } private function render() {