From 5d689358cebe90fce09bdd8c8a8e305737bb752c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= Date: Tue, 26 Sep 2017 14:13:45 +0200 Subject: [PATCH] Additional html-output functions. generateHtmlOutput(out,newLine) can be used to insert preformated html-markdown (via innerHTML). appendHtmlOutput(out,newLine) can be used to directly append DOM-Elements to the prompt-container. --- bin/classes/Prompt.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/classes/Prompt.js b/bin/classes/Prompt.js index 3c6e1ce..5ad9d92 100644 --- a/bin/classes/Prompt.js +++ b/bin/classes/Prompt.js @@ -85,6 +85,29 @@ class Prompt extends Shell{ return this.generateRow() } } + + // Could be integrated in generateOutput() with an additional parameter "html = false" and + // if(html){pre.innerHTML=out} else {pre.textContent=out} + generateHtmlOutput(out = '', newLine = true) { + if (Array.isArray(out)) { + out = out.join("\n") + } + const pre = document.createElement('pre') + pre.innerHTML = out + pre.className = 'terminal-output' + this.container.appendChild(pre) + if (newLine) { + return this.generateRow() + } + } + + appendHtmlOutput(out, newLine = true) { + out.className += ' terminal-output' + this.container.appendChild(out) + if (newLine) { + return this.generateRow() + } + } clear() { this.container.innerHTML = ''