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.WindowContext;
import kernel.ui.WindowManager; import kernel.ui.WindowManager;
import lib.TermWriteable; import kernel.ui.TermWriteable;
import lib.TermIO; import lib.TermIO;
#if webconsole #if webconsole
import kernel.net.Net; import kernel.net.Net;
import util.Debug; import util.Debug;
#end #end
/** /**
Log messages to specified output. Log messages to specified output.
**/ **/
@ -29,34 +30,49 @@ class Log {
} }
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) { 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 #if webconsole
Debug.printWeb("[INFO][" + pos.className + "]: " + Std.string(msg)); Debug.printWeb(logLine("INFO",pos,msg));
#end #end
} }
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) { 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 #if webconsole
Debug.printWeb("[WARN][" + pos.className + "]: " + Std.string(msg)); Debug.printWeb(logLine("WARN",pos,msg));
#end #end
} }
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) { 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 #if webconsole
Debug.printWeb("[ERRO][" + pos.className + "]: " + Std.string(msg)); Debug.printWeb(logLine("ERRO",pos,msg));
#end #end
} }
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) { 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 #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 #end
} }
public static function moveToOutput(addr:String) { public static function moveToOutput(addr:String) {
WindowManager.instance.focusContextToOutput(context, addr); 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; using tink.CoreApi;
import lib.TermWriteable; import kernel.ui.TermWriteable;
import cc.Term; import cc.Term;
import util.Vec.Vec2; import util.Vec.Vec2;
import util.Color; import util.Color;

View File

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

View File

@ -22,22 +22,6 @@ enum PackageTypes {
public final data:Dynamic; public final data:Dynamic;
public var ttl: Int; 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. Create package that can be used as a response.
**/ **/

View File

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

View File

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

View File

@ -1,11 +1,17 @@
package kernel.ui; package kernel.ui;
using tink.CoreApi;
import util.Vec.Vec2; import util.Vec.Vec2;
import util.Color; 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 { class TermBuffer implements TermWriteable {
/** /**
format [y][x]. First index is the line. Second index the char in the line. 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 cursorPos:Vec2<Int> = {x: 0, y: 0};
private var currentTextColor:Color = White; private var currentTextColor:Color = White;
private var currentBgColor:Color = Black; 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 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() { private function new() {
this.onResizeTrigger = Signal.trigger();
this.onResize = onResizeTrigger.asSignal(); this.onResize = onResizeTrigger.asSignal();
initScreenBuffer(size); initScreenBuffer(size);
} }
@ -126,11 +132,11 @@ class TermBuffer implements TermWriteable {
} }
public function getCursorBlink():Bool { public function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException(); return this.cursorBlink;
} }
public function setCursorBlink(blink:Bool) { public function setCursorBlink(blink:Bool) {
// TODO this.cursorBlink = blink;
} }
public function getSize():Vec2<Int> { public function getSize():Vec2<Int> {
@ -164,7 +170,7 @@ class TermBuffer implements TermWriteable {
} }
public function isColor():Bool { public function isColor():Bool {
throw new haxe.exceptions.NotImplementedException(); return true; // Lets return true for now.
} }
public function reset() { public function reset() {

View File

@ -1,4 +1,4 @@
package lib; package kernel.ui;
using tink.CoreApi; using tink.CoreApi;
@ -34,8 +34,8 @@ interface TermWriteable {
public function getBackgroundColor():Color; public function getBackgroundColor():Color;
public function setBackgroundColor(color:Color):Void; public function setBackgroundColor(color:Color):Void;
public function isColor():Bool; public function isColor():Bool;
// setPaletteColor(...) // public function setPaletteColor(...);
// getPaletteColor(colour) // public function getPaletteColor(colour);
/** /**
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White. 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.Vec.Vec2;
import util.Color; 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 { class VirtualTermWriter implements TermWriteable extends TermBuffer {
private static final defaultSize:Vec2<Int> = {x: 50, y: 50}; 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 enabled:Bool = false;
private var onResizeLink:CallbackLink; private var onResizeLink:CallbackLink;
public function new(?target:TermWriteable) { @:allow(kernel.ui)
private function new(?target:TermWriteable) {
setTarget(target); setTarget(target);
if (enabled) { if (enabled) {
@ -52,6 +57,8 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
setSuperSize(newSize); setSuperSize(newSize);
}); });
newTarget.reset();
target = newTarget; target = newTarget;
} }
} }
@ -95,11 +102,18 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
} }
public override function getCursorBlink():Bool { 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) { public override function setCursorBlink(blink:Bool) {
// TODO if (isEnabled()){
target.setCursorBlink(blink);
}
super.setCursorBlink(blink);
} }
public override function getSize():Vec2<Int> { public override function getSize():Vec2<Int> {

View File

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

View File

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

View File

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