1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { DOMConsole } from "../io/domConsole";
- import { getInstance } from "../services/localizedStringsService";
- const LocalizedStrings = getInstance();
- export class TestConsole {
- constructor (inputList) {
- this.index = 0;
- this.inputList = inputList;
- this.list = [];
- }
- write (text) {
- this._appendText(text, DOMConsole.USER);
- }
- info (text) {
- this._appendText(text, DOMConsole.INFO);
- }
- err (text) {
- this._appendText(text, DOMConsole.ERR);
- }
- _appendText (text) {
- this.list.push(text);
- }
- getClassForType (type) {
- switch (type) {
- case DOMConsole.USER:
- return "ivprog-term-userText";
- case DOMConsole.INFO:
- return "ivprog-term-info";
- case DOMConsole.ERR:
- return "ivprog-term-error";
- }
- }
- requestInput () {
- const promise = new Promise( (resolve, reject) => {
- if(this.index < this.inputList.length) {
- resolve(this.inputList[this.index]);
- this.index++;
- } else {
- reject(new Error(LocalizedStrings.getError("exceeded_input_request")));
- }
- });
- return promise
- }
- sendOutput (text) {
- const output = ""+text;
- output.split("\n").forEach(t => {
- t = t.replace(/\t/g,'	');
- this.write(t)
- });
- }
- }
|