testConsole.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { DOMConsole } from "../io/domConsole";
  2. import { getInstance } from "../services/localizedStringsService";
  3. const LocalizedStrings = getInstance();
  4. export class TestConsole {
  5. constructor (inputList) {
  6. this.index = 0;
  7. this.inputList = inputList;
  8. this.list = [];
  9. }
  10. write (text) {
  11. this._appendText(text, DOMConsole.USER);
  12. }
  13. info (text) {
  14. this._appendText(text, DOMConsole.INFO);
  15. }
  16. err (text) {
  17. this._appendText(text, DOMConsole.ERR);
  18. }
  19. _appendText (text) {
  20. this.list.push(text);
  21. }
  22. getClassForType (type) {
  23. switch (type) {
  24. case DOMConsole.USER:
  25. return "ivprog-term-userText";
  26. case DOMConsole.INFO:
  27. return "ivprog-term-info";
  28. case DOMConsole.ERR:
  29. return "ivprog-term-error";
  30. }
  31. }
  32. requestInput (callback) {
  33. if(this.index < this.inputList.length) {
  34. callback(this.inputList[this.index]);
  35. this.index++;
  36. } else {
  37. throw new Error(LocalizedStrings.getError("exceeded_input_request"));
  38. }
  39. }
  40. sendOutput (text) {
  41. const output = ""+text;
  42. output.split("\n").forEach(t => {
  43. t = t.replace(/\t/g,'&#9;');
  44. this.write(t)
  45. });
  46. }
  47. }