outputTest.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. let output = '' + text;
  19. if (output.indexOf('\n') !== -1) {
  20. const outputList = output.split('\n');
  21. let last = outputList.pop();
  22. outputList.forEach( t => {
  23. t = t.replace(/\t/g, '  ');
  24. t = t.replace(/\s/g, " ");
  25. if (t.length == 0)
  26. this.currentLine = null;
  27. else
  28. this.write(t, true);
  29. });
  30. last = last.replace(/\t/g, '  ');
  31. last = last.replace(/\s/g, " ");
  32. if (last.length != 0)
  33. this.write(last);
  34. } else {
  35. output = output.replace(/\t/g, '  ');
  36. output = output.replace(/\s/g, " ");
  37. this.write(output);
  38. }
  39. }
  40. }