Compare commits

..

3 Commits

Author SHA1 Message Date
793639c69d improved home context 2023-03-22 01:32:46 +01:00
4ae6fb4bc7 don't drink and code 2023-03-22 00:57:41 +01:00
9f6bdf6851 removed unused TermIO class 2023-03-21 01:10:58 +01:00
7 changed files with 45 additions and 71 deletions

View File

@@ -7,7 +7,7 @@ General purpose "operation system" for [ComputerCraft](https://tweaked.cc/) buil
- Hardware abstraction - Hardware abstraction
- Virtual screens to switch between multiple GUI apps - Virtual screens to switch between multiple GUI apps
- Reactive UI framework - Reactive UI framework
- Solid base to easily applications - Solid base to easily add applications
# Building # Building

View File

@@ -5,7 +5,7 @@ import cc.OS;
using tink.CoreApi; using tink.CoreApi;
/** /**
Wrapper class for using timer. Wrapper class for using timers.
**/ **/
class Timer { class Timer {
private final timerID:Int; private final timerID:Int;

View File

@@ -3,7 +3,7 @@ package kernel.http;
using tink.CoreApi; using tink.CoreApi;
/** /**
Wrapper for the native Wrapper for the native HTTP request function.
**/ **/
class Http { class Http {
public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> { public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> {

View File

@@ -8,7 +8,7 @@ import lib.Debug;
using tink.CoreApi; using tink.CoreApi;
/** /**
Log messages to specified output. Central logging system.
**/ **/
class Log { class Log {
public static var instance:Log; public static var instance:Log;

View File

@@ -4,7 +4,7 @@ import kernel.log.Log;
using tink.CoreApi; using tink.CoreApi;
/** /**
Virtual network interface that handle Virtual network interface that handles packages to the same id as the sender.
**/ **/
class Loopback implements INetworkInterface { class Loopback implements INetworkInterface {
public static final instance:Loopback = new Loopback(); public static final instance:Loopback = new Loopback();

View File

@@ -1,5 +1,6 @@
package lib; package lib;
import bin.KernelLog;
import lib.ui.elements.UIElement; import lib.ui.elements.UIElement;
import lib.ui.elements.TextElement; import lib.ui.elements.TextElement;
import lib.ui.elements.RootElement; import lib.ui.elements.RootElement;
@@ -80,32 +81,56 @@ class HomeContext {
} }
private function handleSelectContext(contextId:Int) { private function handleSelectContext(contextId:Int) {
if (workspaces[contextId] != null) { if (workspaces[contextId] == null) {
return;
}
focusContext(contextId); focusContext(contextId);
} else { }
private function addTerminal(){
var newContext = WindowManager.instance.createNewBufferedContext(); var newContext = WindowManager.instance.createNewBufferedContext();
// Create new terminal // Create new terminal
var term = new Terminal(); var term = new Terminal();
term.invoke(newContext); term.invoke(newContext);
addContextToWorkspace(newContext, contextId); var contextID = addContextNextWorkspace(newContext);
focusContext(contextId); if (contextID == -1) {
return;
} }
focusContext(contextID);
}
private function addLog(){
var newContext = WindowManager.instance.createNewBufferedContext();
// Create new terminal
var term = new KernelLog();
term.invoke(newContext);
var contextID = addContextNextWorkspace(newContext);
if (contextID == -1) {
return;
}
focusContext(contextID);
} }
private function render() { private function render() {
ctx.clear(); ctx.clear();
ctx.setCursorBlink(false); ctx.setCursorBlink(false);
var list = [ var workspaceIDs:Array<Int> = [for (k=>v in workspaces) k];
for (i in 0...MAX_CONTEXT) workspaces.exists(i) ? 'Switch to context ${i}' : 'Create new Terminal on context ${i}' workspaceIDs.sort((a, b) -> a - b);
];
var children:Array<UIElement> = [ var children:Array<UIElement> = [
for (i => line in list) new TextElement(line, {onClick: this.handleSelectContext.bind(i)}) for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {onClick: this.handleSelectContext.bind(i)})
]; ];
children.push(new TextElement('Add Terminal', {onClick: this.addTerminal}));
children.push(new TextElement('Add Log', {onClick: this.addLog}));
renderer.setChildren(children); renderer.setChildren(children);
renderer.render().renderToContext(ctx); renderer.render().renderToContext(ctx);

View File

@@ -1,51 +0,0 @@
package lib;
import lib.Color;
import kernel.ui.TermWriteable;
/**
Helpfull class for writing onto a `TermWriteable`.
**/
class TermIO {
private var output:TermWriteable;
public function new(output:TermWriteable) {
this.output = output;
output.reset();
output.setCursorPos(0, 0);
}
public function writeLn(text:String, ?textColor:Color) {
if (textColor != null) {
output.setTextColor(textColor);
}
var size = output.getSize();
var cPos = output.getCursorPos();
if (cPos.y >= size.y){
newLine();
}
for (i in 0...Math.floor(text.length / size.x) + 1) {
output.write(text.substr(i * size.x, size.x));
newLine();
}
if (textColor != null) {
output.setTextColor(White);
}
}
private function newLine() {
var cPos = output.getCursorPos();
if (cPos.y == output.getSize().y) {
output.scroll(1);
output.setCursorPos(0, cPos.y - 1);
} else {
output.setCursorPos(0, cPos.y + 1);
}
}
}