1
0

domOutput.js 629 B

12345678910111213141516171819202122232425262728
  1. import { Output } from './output';
  2. export class DOMOutput extends Output {
  3. constructor (selector) {
  4. super();
  5. let id = selector;
  6. if (selector[0] == '#') {
  7. id = selector.substring(1);
  8. }
  9. this.el = document.getElementById(id);
  10. }
  11. sendOutput (text) {
  12. text = text.replace("\n", '</br>');
  13. text = text.replace(/\t/g,'&#9;');
  14. const span = document.createElement('span');
  15. span.classList.add('ivprog-io-output-text');
  16. span.innerHTML = text;
  17. this.el.append(span);
  18. }
  19. clear () {
  20. while(this.el.childNodes.length > 0) {
  21. this.el.removeChild(this.el.firstChild);
  22. }
  23. }
  24. }