log.js 904 B

12345678910111213141516171819202122232425262728
  1. var num_lines = 0;
  2. Vue.component("log", {
  3. template: `<textarea v-bind:id="jp_props.id" :class="jp_props.classes" :style="jp_props.style" disabled></textarea>`,
  4. mounted() {
  5. comp_dict[this.$props.jp_props.id] = this;
  6. },
  7. methods: {
  8. push(line) {
  9. const decoded = decodeURIComponent(line);
  10. const textarea = document.getElementById(this.$props.jp_props.id);
  11. textarea.innerHTML += (num_lines ? "\n" : "") + decoded;
  12. textarea.scrollTop = textarea.scrollHeight;
  13. num_lines += decoded.split("\n").length;
  14. const max_lines = this.$props.jp_props.options.max_lines;
  15. while (max_lines != null && num_lines > max_lines) {
  16. const index = textarea.innerHTML.indexOf("\n");
  17. if (index == -1) break;
  18. textarea.innerHTML = textarea.innerHTML.slice(index + 1);
  19. num_lines -= 1;
  20. }
  21. },
  22. },
  23. props: {
  24. jp_props: Object,
  25. },
  26. });