52 lines
949 B
Haxe
52 lines
949 B
Haxe
package lib;
|
|
|
|
import lib.Color;
|
|
import kernel.ui.TermWriteable;
|
|
|
|
/**
|
|
Helpfull class for writing onto a `TermWriteable`.
|
|
**/
|
|
class TermIO {
|
|
private var output:TermWriteable;
|
|
|
|
public function new(output:TermWriteable) {
|
|
this.output = output;
|
|
|
|
output.reset();
|
|
output.setCursorPos(0, 0);
|
|
}
|
|
|
|
public function writeLn(text:String, ?textColor:Color) {
|
|
if (textColor != null) {
|
|
output.setTextColor(textColor);
|
|
}
|
|
|
|
var size = output.getSize();
|
|
var cPos = output.getCursorPos();
|
|
|
|
if (cPos.y >= size.y){
|
|
newLine();
|
|
}
|
|
|
|
for (i in 0...Math.floor(text.length / size.x) + 1) {
|
|
output.write(text.substr(i * size.x, size.x));
|
|
newLine();
|
|
}
|
|
|
|
if (textColor != null) {
|
|
output.setTextColor(White);
|
|
}
|
|
}
|
|
|
|
private function newLine() {
|
|
var cPos = output.getCursorPos();
|
|
|
|
if (cPos.y == output.getSize().y) {
|
|
output.scroll(1);
|
|
output.setCursorPos(0, cPos.y - 1);
|
|
} else {
|
|
output.setCursorPos(0, cPos.y + 1);
|
|
}
|
|
}
|
|
}
|