125 lines
2.3 KiB
Haxe
125 lines
2.3 KiB
Haxe
package kernel.peripherals;
|
|
|
|
import cc.Peripheral;
|
|
import lib.Pos;
|
|
import cc.Term.TerminalSize;
|
|
import kernel.ui.TermWriteable;
|
|
import lib.Vec.Vec2;
|
|
import lib.Color;
|
|
|
|
using tink.CoreApi;
|
|
|
|
class Screen implements TermWriteable implements IPeripheral {
|
|
public static inline final TYPE_NAME:String = "monitor";
|
|
|
|
private final nativ:cc.periphs.Monitor.Monitor;
|
|
private final addr:String;
|
|
|
|
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
|
|
|
|
public final onResize:Signal<Vec2<Int>>;
|
|
|
|
@:allow(kernel.peripherals)
|
|
private function new(addr:String) {
|
|
this.onResize = onResizeTrigger.asSignal();
|
|
|
|
this.nativ = Peripheral.wrap(addr);
|
|
this.addr = addr;
|
|
|
|
KernelEvents.onMonitorResize.handle(addr -> {
|
|
if (addr == this.addr) {
|
|
onResizeTrigger.trigger(getSize());
|
|
}
|
|
});
|
|
|
|
setTextScale(0.5);
|
|
}
|
|
|
|
public function getAddr():String {
|
|
return this.addr;
|
|
}
|
|
|
|
public function getType():String {
|
|
return TYPE_NAME;
|
|
}
|
|
|
|
public function getTextScale():Float {
|
|
return nativ.getTextScale();
|
|
}
|
|
|
|
public function setTextScale(scale:Float) {
|
|
nativ.setTextScale(scale);
|
|
}
|
|
|
|
public function write(text:String) {
|
|
nativ.write(text);
|
|
}
|
|
|
|
public function scroll(y:Int) {
|
|
nativ.scroll(y);
|
|
}
|
|
|
|
public function getCursorPos():Pos {
|
|
var rtn = nativ.getCursorPos();
|
|
return {
|
|
x: rtn.x - 1,
|
|
y: rtn.y - 1
|
|
}
|
|
}
|
|
|
|
public function setCursorPos(x:Int, y:Int) {
|
|
nativ.setCursorPos(x + 1, y + 1);
|
|
}
|
|
|
|
public function getCursorBlink():Bool {
|
|
return nativ.getCursorBlink();
|
|
}
|
|
|
|
public function setCursorBlink(blink:Bool) {
|
|
nativ.setCursorBlink(blink);
|
|
}
|
|
|
|
public function getSize():Vec2<Int> {
|
|
var size:TerminalSize = nativ.getSize();
|
|
return {
|
|
x: size.width,
|
|
y: size.height,
|
|
}
|
|
}
|
|
|
|
public function clear() {
|
|
nativ.clear();
|
|
}
|
|
|
|
public function clearLine() {
|
|
nativ.clearLine();
|
|
}
|
|
|
|
public function getTextColor():Color {
|
|
return nativ.getTextColor();
|
|
}
|
|
|
|
public function setTextColor(color:Color) {
|
|
nativ.setTextColor(color);
|
|
}
|
|
|
|
public function getBackgroundColor():Color {
|
|
return nativ.getBackgroundColor();
|
|
}
|
|
|
|
public function setBackgroundColor(color:Color) {
|
|
nativ.setBackgroundColor(color);
|
|
}
|
|
|
|
public function isColor():Bool {
|
|
return nativ.isColor();
|
|
}
|
|
|
|
public function reset() {
|
|
this.setBackgroundColor(Black);
|
|
this.setTextColor(White);
|
|
this.clear();
|
|
this.setCursorPos(0,0);
|
|
}
|
|
}
|