1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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 (callback) {
- if(this.index < this.inputList.length) {
- callback(this.inputList[this.index]);
- this.index++;
- } else {
- throw new Error(LocalizedStrings.getError("exceeded_input_request"));
- }
- }
- sendOutput (text) {
- const output = ""+text;
- output.split("\n").forEach(t => {
- t = t.replace(/\t/g,'	');
- this.write(t)
- });
- }
- }
|