Skip to content

Commit ddce84b

Browse files
committed
fix line formatting for multi-line log
1 parent 9b57e5e commit ddce84b

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/renderer/components/Experiment/Tasks/PollingOutputTerminal.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const PollingOutputTerminal: React.FC<PollingOutputTerminalProps> = ({
5656
const line = lineQueue.current.shift()!;
5757

5858
try {
59-
termRef.current.write(line.replace(/\n$/, '\r\n'));
59+
// Write the line and add a newline
60+
termRef.current.write(line + '\r\n');
6061
} catch (error) {
6162
console.error('PollingOutputTerminal: Error writing to terminal:', error);
6263
}
@@ -80,7 +81,7 @@ const PollingOutputTerminal: React.FC<PollingOutputTerminalProps> = ({
8081
if (!response.ok) {
8182
throw new Error(`HTTP ${response.status}`);
8283
}
83-
return response.text();
84+
return response.json();
8485
},
8586
{
8687
refreshInterval: refreshInterval,
@@ -139,24 +140,27 @@ const PollingOutputTerminal: React.FC<PollingOutputTerminalProps> = ({
139140
};
140141

141142
// Process new content when data changes
142-
if (outputData && outputData !== lastContent) {
143-
// Only process new lines (content that wasn't there before)
144-
if (lastContent) {
145-
const newContent = outputData.slice(lastContent.length);
146-
if (newContent.trim()) {
147-
const newLines = newContent.split('\n').filter(line => line.trim());
148-
addLinesOneByOne(newLines);
143+
if (outputData && Array.isArray(outputData)) {
144+
const currentLines = outputData.join('\n');
145+
if (currentLines !== lastContent) {
146+
// Only process new lines (content that wasn't there before)
147+
if (lastContent) {
148+
const newContent = currentLines.slice(lastContent.length);
149+
if (newContent.trim()) {
150+
// Split new content by newlines
151+
const newLines = newContent.split('\n').filter(line => line.trim());
152+
addLinesOneByOne(newLines);
153+
}
154+
} else {
155+
// First time - clear the loading message and add all content
156+
if (termRef.current) {
157+
termRef.current.clear();
158+
}
159+
addLinesOneByOne(outputData);
149160
}
150-
} else {
151-
// First time - clear the loading message and add all content
152-
if (termRef.current) {
153-
termRef.current.clear();
154-
}
155-
const lines = outputData.split('\n').filter(line => line.trim());
156-
addLinesOneByOne(lines);
157-
}
158161

159-
setLastContent(outputData);
162+
setLastContent(currentLines);
163+
}
160164
}
161165

162166
// Handle errors

0 commit comments

Comments
 (0)