This commit is contained in:
2022-02-21 15:35:37 +01:00
parent f21e49c520
commit 0ad907f74a
33 changed files with 788 additions and 815 deletions

View File

@@ -7,159 +7,159 @@ import util.Color;
import lib.TermWriteable;
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};
private var target: TermWriteable;
private var enabled:Bool = false;
private var onResizeLink: CallbackLink;
private var target:TermWriteable;
private var enabled:Bool = false;
private var onResizeLink:CallbackLink;
public function new(?target: TermWriteable) {
setTarget(target);
public function new(?target:TermWriteable) {
setTarget(target);
if (enabled){
enable();
}
if (enabled) {
enable();
}
super();
}
super();
}
public function enable() {
if (target != null){
enabled = true;
super.copyBufferToTarget(target);
}
}
public function enable() {
if (target != null) {
enabled = true;
super.copyBufferToTarget(target);
}
}
public function disable() {
enabled = false;
}
public function disable() {
enabled = false;
}
public inline function isEnabled(): Bool {
return enabled;
}
public inline function isEnabled():Bool {
return enabled;
}
public function setTarget(newTarget: TermWriteable) {
if (newTarget != null){
super.setSize(newTarget.getSize());
public function setTarget(newTarget:TermWriteable) {
if (newTarget != null) {
super.setSize(newTarget.getSize());
// Remove old target event listner
if (onResizeLink != null){
onResizeLink.cancel();
}
// Remove old target event listner
if (onResizeLink != null) {
onResizeLink.cancel();
}
// Add new target event listner
onResizeLink = newTarget.onResize.handle(newSize -> {
setSuperSize(newSize);
});
// Add new target event listner
onResizeLink = newTarget.onResize.handle(newSize -> {
setSuperSize(newSize);
});
target = newTarget;
}
}
target = newTarget;
}
}
private function setSuperSize(size: Vec2<Int>) {
super.setSize(target.getSize());
}
//
// TermWriteable functions.
//
private function setSuperSize(size:Vec2<Int>) {
super.setSize(target.getSize());
}
//
// TermWriteable functions.
//
public override function write(text:String) {
if (isEnabled()){
target.write(text);
}
super.write(text);
}
if (isEnabled()) {
target.write(text);
}
super.write(text);
}
public override function scroll(y:Int) {
if (isEnabled()){
target.scroll(y);
}
super.scroll(y);
}
if (isEnabled()) {
target.scroll(y);
}
super.scroll(y);
}
public override function getCursorPos():Vec2<Int> {
if (isEnabled()){
return target.getCursorPos();
}else{
return super.getCursorPos();
}
if (isEnabled()) {
return target.getCursorPos();
} else {
return super.getCursorPos();
}
}
public override function setCursorPos(x:Int, y:Int) {
if (isEnabled()){
target.setCursorPos(x,y);
}
if (isEnabled()) {
target.setCursorPos(x, y);
}
super.setCursorPos(x,y);
}
super.setCursorPos(x, y);
}
public override function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException();
}
public override function setCursorBlink(blink:Bool) {
// TODO
}
// TODO
}
public override function getSize():Vec2<Int> {
// TODO: make sense ?
if (target != null){
return target.getSize();
}
// TODO: make sense ?
if (target != null) {
return target.getSize();
}
return defaultSize;
return defaultSize;
}
public override function clear() {
if (isEnabled()){
target.clear();
}
super.clear();
}
if (isEnabled()) {
target.clear();
}
super.clear();
}
public override function clearLine() {
if (isEnabled()){
target.clearLine();
}
if (isEnabled()) {
target.clearLine();
}
super.clearLine();
}
super.clearLine();
}
public override function getTextColor():Color {
if (isEnabled()){
return target.getTextColor();
}
if (isEnabled()) {
return target.getTextColor();
}
return super.getTextColor();
return super.getTextColor();
}
public override function setTextColor(colour:Color) {
if (isEnabled()){
target.setTextColor(colour);
}
if (isEnabled()) {
target.setTextColor(colour);
}
super.setTextColor(colour);
}
super.setTextColor(colour);
}
public override function getBackgroundColor():Color {
if (isEnabled()){
return target.getBackgroundColor();
}
if (isEnabled()) {
return target.getBackgroundColor();
}
return super.getBackgroundColor();
return super.getBackgroundColor();
}
public override function setBackgroundColor(color:Color) {
if (isEnabled()){
target.setBackgroundColor(color);
}
if (isEnabled()) {
target.setBackgroundColor(color);
}
super.setBackgroundColor(color);
}
super.setBackgroundColor(color);
}
public override function isColor():Bool {
throw new haxe.exceptions.NotImplementedException();
}
}
}