106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Haxe
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Haxe
		
	
	
	
	
	
package kernel;
 | 
						|
 | 
						|
import lib.ScreenPos;
 | 
						|
import kernel.ui.ITermWriteable;
 | 
						|
import cc.Term;
 | 
						|
import lib.Vec.Vec2;
 | 
						|
import lib.Color;
 | 
						|
 | 
						|
using tink.CoreApi;
 | 
						|
 | 
						|
/**
 | 
						|
	Represents the main computer screen.
 | 
						|
**/
 | 
						|
class MainTerm implements ITermWriteable {
 | 
						|
	/**
 | 
						|
		Depends on: KernelEvents,
 | 
						|
	**/
 | 
						|
	public static var instance:MainTerm;
 | 
						|
 | 
						|
	public var onResize(default, null):Signal<Vec2<Int>>;
 | 
						|
 | 
						|
	private var onResizeTrigger:SignalTrigger<Vec2<Int>>;
 | 
						|
 | 
						|
	@:allow(kernel.Init)
 | 
						|
	private function new() {
 | 
						|
		this.onResizeTrigger = Signal.trigger();
 | 
						|
		this.onResize = this.onResizeTrigger.asSignal();
 | 
						|
 | 
						|
		KernelEvents.onTermResize.handle(_ -> {
 | 
						|
			onResizeTrigger.trigger(getSize());
 | 
						|
		});
 | 
						|
	}
 | 
						|
 | 
						|
	public function write(text:String) {
 | 
						|
		Term.write(text);
 | 
						|
	}
 | 
						|
 | 
						|
	public function scroll(y:Int) {
 | 
						|
		Term.scroll(y);
 | 
						|
	}
 | 
						|
 | 
						|
	public function getCursorPos():ScreenPos {
 | 
						|
		var rtn = Term.getCursorPos();
 | 
						|
		return {
 | 
						|
			x: rtn.x - 1,
 | 
						|
			y: rtn.y - 1
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	public function setCursorPos(x:Int, y:Int) {
 | 
						|
		Term.setCursorPos(x + 1, y + 1);
 | 
						|
	}
 | 
						|
 | 
						|
	public function getCursorBlink():Bool {
 | 
						|
		// Missing in api
 | 
						|
		throw new haxe.exceptions.NotImplementedException();
 | 
						|
	}
 | 
						|
 | 
						|
	public function setCursorBlink(blink:Bool) {
 | 
						|
		Term.setCursorBlink(blink);
 | 
						|
	}
 | 
						|
 | 
						|
	public function getSize():ScreenPos {
 | 
						|
		var rtn = Term.getSize();
 | 
						|
		return {
 | 
						|
			x: rtn.width,
 | 
						|
			y: rtn.height,
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	public function clear() {
 | 
						|
		Term.clear();
 | 
						|
	}
 | 
						|
 | 
						|
	public function clearLine() {
 | 
						|
		Term.clearLine();
 | 
						|
	}
 | 
						|
 | 
						|
	public function getTextColor():Color {
 | 
						|
		return Term.getTextColor();
 | 
						|
	}
 | 
						|
 | 
						|
	public function setTextColor(color:Color) {
 | 
						|
		Term.setTextColor(color);
 | 
						|
	}
 | 
						|
 | 
						|
	public function getBackgroundColor():Color {
 | 
						|
		return Term.getBackgroundColor();
 | 
						|
	}
 | 
						|
 | 
						|
	public function setBackgroundColor(color:Color) {
 | 
						|
		Term.setBackgroundColor(color);
 | 
						|
	}
 | 
						|
 | 
						|
	public function isColor():Bool {
 | 
						|
		return Term.isColor();
 | 
						|
	}
 | 
						|
 | 
						|
	public function reset() {
 | 
						|
		this.setBackgroundColor(Black);
 | 
						|
		this.setTextColor(White);
 | 
						|
		this.clear();
 | 
						|
		this.setCursorPos(0, 0);
 | 
						|
	}
 | 
						|
}
 |