a LOT of minor stuff

This commit is contained in:
Djeeberjr 2022-03-05 02:41:30 +01:00
parent ce45bf2726
commit df77704d1c
12 changed files with 90 additions and 56 deletions

View File

@ -2,12 +2,13 @@ package kernel;
import kernel.ui.WindowContext;
import kernel.ui.WindowManager;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
import lib.TermIO;
#if webconsole
import kernel.net.Net;
import util.Debug;
#end
/**
Log messages to specified output.
**/
@ -29,34 +30,49 @@ class Log {
}
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn("[INFO][" + pos.className + "]: " + Std.string(msg));
writer.writeLn(logLine("INFO",pos,msg));
#if webconsole
Debug.printWeb("[INFO][" + pos.className + "]: " + Std.string(msg));
Debug.printWeb(logLine("INFO",pos,msg));
#end
}
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn("[WARN][" + pos.className + "]: " + Std.string(msg), Yellow);
writer.writeLn(logLine("WARN",pos,msg), Yellow);
#if webconsole
Debug.printWeb("[WARN][" + pos.className + "]: " + Std.string(msg));
Debug.printWeb(logLine("WARN",pos,msg));
#end
}
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn("[ERRO][" + pos.className + "]: " + Std.string(msg), Red);
writer.writeLn(logLine("ERRO",pos,msg), Red);
#if webconsole
Debug.printWeb("[ERRO][" + pos.className + "]: " + Std.string(msg));
Debug.printWeb(logLine("ERRO",pos,msg));
#end
}
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn("[DEBG][" + pos.className + "]: " + Std.string(msg), Gray);
writer.writeLn(logLine("DEBG",pos,msg), Gray);
#if webconsole
Debug.printWeb("[DEBG][" + pos.className + "]: " + Std.string(msg));
Debug.printWeb(logLine("DEBG",pos,msg));
#end
}
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
writer.writeLn(logLine("SILY",pos,msg), LightGrey);
#if webconsole
Debug.printWeb(logLine("SILY",pos,msg));
#end
}
public static function moveToOutput(addr:String) {
WindowManager.instance.focusContextToOutput(context, addr);
}
private static function logLine(tag: String,pos: haxe.PosInfos,msg: Dynamic): String {
#if debug
return '[$tag][${pos.className}:${pos.lineNumber}]: ${Std.string(msg)}';
#else
return '[$tag]: ${Std.string(msg)}';
#end
}
}

View File

@ -2,7 +2,7 @@ package kernel;
using tink.CoreApi;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
import cc.Term;
import util.Vec.Vec2;
import util.Color;

View File

@ -18,11 +18,13 @@ class Loopback implements INetworkInterface {
}
public function listen(chan:Int) {
// TODO
if (!this.openChans.contains(chan)){
this.openChans.push(chan);
}
}
public function close(chan:Int) {
// TODO
this.openChans.remove(chan);
}
public function isListening(chan:Int):Bool {
@ -34,7 +36,11 @@ class Loopback implements INetworkInterface {
}
public function send(chan:Int, replyChan:Int, payload:Any) {
if (this.openChans.contains(chan)){
this.onMessageTrigger.trigger(payload);
}else{
Log.silly("Loopback got package on non open channel");
}
}
public function name():String {

View File

@ -22,22 +22,6 @@ enum PackageTypes {
public final data:Dynamic;
public var ttl: Int;
/**
Parse package from an `modem_message` event.
**/
public static function fromEvent(params:Array<Dynamic>):Package {
var payload = params[4];
return {
fromID: params[3],
toID: params[2],
msgID: payload.msgID,
type: payload.type,
data: payload.data,
ttl: payload.ttl,
};
}
/**
Create package that can be used as a response.
**/

View File

@ -6,6 +6,7 @@ import kernel.peripherals.Screen;
using lua.Table;
using Lambda;
using tink.CoreApi;
/**
Class responseable for retrieving peripherals.
@ -54,6 +55,10 @@ class Peripheral {
return this.modes;
}
public function getModem(addr: String): Null<Modem> {
return this.modes.find(item -> item.getAddr() == addr);
}
private function findModems():Void {
var allModems = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "modem");
this.modes = allModems.map(s -> return new Modem((cc.Peripheral.wrap(s) : Dynamic), s));

View File

@ -1,23 +1,23 @@
package kernel.peripherals;
using tink.CoreApi;
import cc.Term.TerminalSize;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
import util.Vec.Vec2;
import util.Color;
using tink.CoreApi;
class Screen implements TermWriteable implements IPeripheral {
private final nativ:cc.periphs.Monitor.Monitor;
private final addr:String;
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
public var onResize(default, null):Signal<Vec2<Int>>;
public final onResize:Signal<Vec2<Int>>;
@:allow(kernel.peripherals)
public function new(nativePeripherals:cc.periphs.Monitor.Monitor, addr:String) {
this.onResizeTrigger = Signal.trigger();
this.onResize = onResizeTrigger.asSignal();
this.nativ = nativePeripherals;
@ -73,7 +73,6 @@ class Screen implements TermWriteable implements IPeripheral {
}
public function getSize():Vec2<Int> {
// FIXME: this will not compile. Has to be changes upstream
var size:TerminalSize = nativ.getSize();
return {
x: size.width,

View File

@ -1,11 +1,17 @@
package kernel.ui;
using tink.CoreApi;
import util.Vec.Vec2;
import util.Color;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
using tink.CoreApi;
/**
A virtual terminal. With this a GUI program can still write to its "screen"
even if its not displayed right now. When the GUI gets displayed again
this buffer will be written to the screen.
**/
class TermBuffer implements TermWriteable {
/**
format [y][x]. First index is the line. Second index the char in the line.
@ -15,14 +21,14 @@ class TermBuffer implements TermWriteable {
private var cursorPos:Vec2<Int> = {x: 0, y: 0};
private var currentTextColor:Color = White;
private var currentBgColor:Color = Black;
private var cursorBlink: Bool = false;
private var size:Vec2<Int> = {x: 51, y: 19}; // Default size set to default size of the main terminal
public var onResize(default, null):Signal<Vec2<Int>>;
public final onResize:Signal<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
public function new() {
this.onResizeTrigger = Signal.trigger();
private function new() {
this.onResize = onResizeTrigger.asSignal();
initScreenBuffer(size);
}
@ -126,11 +132,11 @@ class TermBuffer implements TermWriteable {
}
public function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException();
return this.cursorBlink;
}
public function setCursorBlink(blink:Bool) {
// TODO
this.cursorBlink = blink;
}
public function getSize():Vec2<Int> {
@ -164,7 +170,7 @@ class TermBuffer implements TermWriteable {
}
public function isColor():Bool {
throw new haxe.exceptions.NotImplementedException();
return true; // Lets return true for now.
}
public function reset() {

View File

@ -1,4 +1,4 @@
package lib;
package kernel.ui;
using tink.CoreApi;
@ -34,8 +34,8 @@ interface TermWriteable {
public function getBackgroundColor():Color;
public function setBackgroundColor(color:Color):Void;
public function isColor():Bool;
// setPaletteColor(...)
// getPaletteColor(colour)
// public function setPaletteColor(...);
// public function getPaletteColor(colour);
/**
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White.

View File

@ -4,8 +4,12 @@ using tink.CoreApi;
import util.Vec.Vec2;
import util.Color;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
/**
A term writer that can switch beetween its internal buffer and another termwriter.
The other target is most of the time a real screen
**/
class VirtualTermWriter implements TermWriteable extends TermBuffer {
private static final defaultSize:Vec2<Int> = {x: 50, y: 50};
@ -13,7 +17,8 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
private var enabled:Bool = false;
private var onResizeLink:CallbackLink;
public function new(?target:TermWriteable) {
@:allow(kernel.ui)
private function new(?target:TermWriteable) {
setTarget(target);
if (enabled) {
@ -52,6 +57,8 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
setSuperSize(newSize);
});
newTarget.reset();
target = newTarget;
}
}
@ -95,11 +102,18 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
}
public override function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException();
if (isEnabled()){
return target.getCursorBlink();
}else{
return super.getCursorBlink();
}
}
public override function setCursorBlink(blink:Bool) {
// TODO
if (isEnabled()){
target.setCursorBlink(blink);
}
super.setCursorBlink(blink);
}
public override function getSize():Vec2<Int> {

View File

@ -5,7 +5,7 @@ using tink.CoreApi;
import util.Color;
import kernel.ButtonType;
import util.Vec.Vec2;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
/**
The main object you interact with when writing anything to the screen.

View File

@ -1,8 +1,12 @@
package kernel.ui;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
import kernel.peripherals.Peripherals.Peripheral;
/**
Responsable for creating window context, forwarding UI events to the context
and switching context to real screens.
**/
class WindowManager {
/**
Depends on: KernelEvents, Peripheral
@ -45,9 +49,9 @@ class WindowManager {
});
KernelEvents.instance.onMouseUp.handle(params -> {
// if (currentMainContext != null) {
if (currentMainContext != null) {
currentMainContext.onMouseUpTrigger.trigger(params);
// }
}
});
KernelEvents.instance.onPaste.handle(text -> {

View File

@ -1,7 +1,7 @@
package lib;
import util.Color;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
/**
Helpfull class for writing onto a `TermWriteable`.