outputTest.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. t = " ";
  27. this.write(t, true);
  28. });
  29. last = last.replace(/\t/g, '  ');
  30. last = last.replace(/\s/g, " ");
  31. if (last.length != 0)
  32. this.write(last);
  33. } else {
  34. output = output.replace(/\t/g, '  ');
  35. output = output.replace(/\s/g, " ");
  36. this.write(output);
  37. }
  38. }
  39. }