Browse Source

Fix domConsole.js not properly showing linebreaks when writing the \n
char

Lucas de Souza 3 years ago
parent
commit
55cf8d8802
2 changed files with 22 additions and 16 deletions
  1. 9 5
      css/ivprog-term.css
  2. 13 11
      js/io/domConsole.js

+ 9 - 5
css/ivprog-term.css

@@ -11,18 +11,22 @@
 
 .ivprog-term-userText {
   white-space: pre;
+  height: 1.6rem;
 }
 
 .ivprog-term-userText, .ivprog-term-userInput {
   color: #f2d6d6;
+  height: 1.6rem;
 }
 
 .ivprog-term-info {
   color: #28a628;
+  height: 1.6rem;
 }
 
 .ivprog-term-error {
   color: #df4242;
+  height: 1.6rem;
 }
 
 .ivprog-term-input {
@@ -65,18 +69,18 @@
 .ivprog-term-div::-webkit-scrollbar {
     width: 12px;
 }
- 
+
 .ivprog-term-div::-webkit-scrollbar-track {
-    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
+    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
     -webkit-border-radius: 10px;
     border-radius: 10px;
 }
- 
+
 .ivprog-term-div::-webkit-scrollbar-thumb {
     -webkit-border-radius: 10px;
     border-radius: 10px;
     background: green;
-    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
+    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
 }
 
 /**novas regras bash*/
@@ -116,7 +120,7 @@
   background: #111010;
   /* list-style: none; */
   color: #F8F8FF;
-  
+
   font: 14px 'Andale Mono', Consolas, 'Courier New';
   line-height: 1.6em;
   border: 1px solid #CCCCCC;

+ 13 - 11
js/io/domConsole.js

@@ -191,7 +191,7 @@ export class DOMConsole {
   }
 
   async _appendText (text, type, newLine = false) {
-    console.debug("Caling appendText");
+    // console.debug("Caling appendText");
     const write_time = Date.now();
     this.pending_writes.push(0);
     await Utils.sleep(5);
@@ -209,7 +209,7 @@ export class DOMConsole {
     }
     this.currentLine.innerHTML += this.getOutputText(text);
     if (newLine) {
-      console.debug("append newline");
+      // console.debug("append newline");
       this.currentLine = null;
     }
     this.scrollTerm();
@@ -228,6 +228,9 @@ export class DOMConsole {
     textDiv.classList.add(divClass);
     if (filter) textDiv.innerHTML = this.getOutputText(text);
     else textDiv.innerHTML = `<span>${text}</span>`;
+    if (this.currentLine != null && this.currentLine.innerHTML.length === 0) {
+      this.termDiv.removeChild(this.currentLine);
+    }
     this.termDiv.insertBefore(textDiv, this.inputDiv);
     this.currentLine = null;
     this.scrollTerm();
@@ -365,22 +368,21 @@ export class DOMConsole {
   }
 
   sendOutput (text) {
-    // console.debug(text);
+    //console.debug(text);
     let output = "" + text;
     if (output.indexOf("\n") !== -1) {
-      // console.debug("newline");
+      //console.debug("newline");
       const outputList = output.split("\n");
       let i = 0;
       for (; i < outputList.length - 1; i += 1) {
-        // console.debug("newline write");
+        //console.debug("newline write");
         let t = outputList[i];
         t = t.replace(/\t/g, "&#x0020;&#x0020;");
         t = t.replace(/\s/g, "&#x0020;");
-        if (t.length == 0) {
-          // t = "&nbsp;";
-          // console.debug('Empty string');
-          this.currentLine = null;
-        } else this.write(t, true);
+        if (t.length !== 0) {
+          this.write(t);
+        }
+        this.write("", true);
       }
       let t = outputList[i];
       t = t.replace(/\t/g, "&#x0020;&#x0020;");
@@ -390,7 +392,7 @@ export class DOMConsole {
       // console.debug("no newline");
       output = output.replace(/\t/g, "&#x0020;&#x0020;");
       output = output.replace(/\s/g, "&#x0020;");
-      this.write(output);
+      if (output.length != 0) this.write(output);
     }
   }