Skip to content

Commit 0773895

Browse files
committed
fix: properly format multiline output with newlines and indentation
1 parent 60d36c9 commit 0773895

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

script.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,16 @@ function handleCommand(input) {
178178

179179
function displayOutput(text, success = true) {
180180
const timestamp = new Date().toLocaleTimeString();
181-
const line = `[${timestamp}] ${text}`;
182-
outputElement.innerHTML += `<div class="${success ? '' : 'error'}">${line}</div>`;
181+
// Replace escaped newlines with actual newlines and handle indentation
182+
const formattedText = text.replace(/\\n/g, '\n').split('\n').map(line => line.trim()).join('\n');
183+
const lines = formattedText.split('\n');
184+
185+
lines.forEach((line, index) => {
186+
// Only add timestamp to first line
187+
const prefix = index === 0 ? `[${timestamp}] ` : ' ';
188+
outputElement.innerHTML += `<div class="${success ? '' : 'error'}">${prefix}${line}</div>`;
189+
});
190+
183191
scrollToBottom();
184192
}
185193

0 commit comments

Comments
 (0)