outputTest.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Output } from "./../io/output";
  2. export class OutputTest extends Output {
  3. constructor () {
  4. super();
  5. this.list = [];
  6. this.currentLine = null;
  7. }
  8. write (text, newLine = false) {
  9. if (this.currentLine == null) {
  10. this.currentLine = this.list.push("") - 1;
  11. }
  12. this.list[this.currentLine] += text;
  13. if (newLine) {
  14. this.currentLine = null;
  15. }
  16. }
  17. sendOutput (text) {
  18. const output = "" + text;
  19. if (output.indexOf("\n") !== -1) {
  20. const outputList = output.split("\n");
  21. const last = outputList.pop();
  22. outputList.forEach((t) => {
  23. //t = t.replace(/\t/g, '  ');
  24. //t = t.replace(/\s/g, " ");
  25. if (t.length == 0) this.currentLine = null;
  26. else this.write(t, true);
  27. });
  28. //last = last.replace(/\t/g, '  ');
  29. //last = last.replace(/\s/g, " ");
  30. if (last.length != 0) this.write(last);
  31. } else {
  32. //output = output.replace(/\t/g, '  ');
  33. //output = output.replace(/\s/g, " ");
  34. this.write(output);
  35. }
  36. }
  37. }