Compare commits
3 Commits
347e210f5f
...
793639c69d
| Author | SHA1 | Date | |
|---|---|---|---|
| 793639c69d | |||
| 4ae6fb4bc7 | |||
| 9f6bdf6851 |
@@ -7,7 +7,7 @@ General purpose "operation system" for [ComputerCraft](https://tweaked.cc/) buil
|
||||
- Hardware abstraction
|
||||
- Virtual screens to switch between multiple GUI apps
|
||||
- Reactive UI framework
|
||||
- Solid base to easily applications
|
||||
- Solid base to easily add applications
|
||||
|
||||
# Building
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import cc.OS;
|
||||
using tink.CoreApi;
|
||||
|
||||
/**
|
||||
Wrapper class for using timer.
|
||||
Wrapper class for using timers.
|
||||
**/
|
||||
class Timer {
|
||||
private final timerID:Int;
|
||||
|
||||
@@ -3,7 +3,7 @@ package kernel.http;
|
||||
using tink.CoreApi;
|
||||
|
||||
/**
|
||||
Wrapper for the native
|
||||
Wrapper for the native HTTP request function.
|
||||
**/
|
||||
class Http {
|
||||
public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> {
|
||||
|
||||
@@ -8,7 +8,7 @@ import lib.Debug;
|
||||
using tink.CoreApi;
|
||||
|
||||
/**
|
||||
Log messages to specified output.
|
||||
Central logging system.
|
||||
**/
|
||||
class Log {
|
||||
public static var instance:Log;
|
||||
|
||||
@@ -4,7 +4,7 @@ import kernel.log.Log;
|
||||
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 {
|
||||
public static final instance:Loopback = new Loopback();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package lib;
|
||||
|
||||
import bin.KernelLog;
|
||||
import lib.ui.elements.UIElement;
|
||||
import lib.ui.elements.TextElement;
|
||||
import lib.ui.elements.RootElement;
|
||||
@@ -80,32 +81,56 @@ class HomeContext {
|
||||
}
|
||||
|
||||
private function handleSelectContext(contextId:Int) {
|
||||
if (workspaces[contextId] != null) {
|
||||
if (workspaces[contextId] == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
focusContext(contextId);
|
||||
} else {
|
||||
}
|
||||
|
||||
private function addTerminal(){
|
||||
var newContext = WindowManager.instance.createNewBufferedContext();
|
||||
|
||||
// Create new terminal
|
||||
var term = new Terminal();
|
||||
term.invoke(newContext);
|
||||
|
||||
addContextToWorkspace(newContext, contextId);
|
||||
focusContext(contextId);
|
||||
var contextID = addContextNextWorkspace(newContext);
|
||||
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() {
|
||||
ctx.clear();
|
||||
ctx.setCursorBlink(false);
|
||||
|
||||
var list = [
|
||||
for (i in 0...MAX_CONTEXT) workspaces.exists(i) ? 'Switch to context ${i}' : 'Create new Terminal on context ${i}'
|
||||
];
|
||||
var workspaceIDs:Array<Int> = [for (k=>v in workspaces) k];
|
||||
workspaceIDs.sort((a, b) -> a - b);
|
||||
|
||||
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.render().renderToContext(ctx);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user