Skip to content

Commit 5c16f8d

Browse files
author
Akos Kitta
committed
From now on, monitor widget does not expect EOL.
Otherwise, if client code does not contain `Serial.write('\n')`, the widget does not show any output. Closes arduino/arduino-pro-ide#201 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 807b2ad commit 5c16f8d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

arduino-ide-extension/src/browser/monitor/monitor-widget.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,20 @@ export class SerialMonitorOutput extends React.Component<SerialMonitorOutput.Pro
288288

289289
componentDidMount(): void {
290290
this.scrollToBottom();
291-
let chunk = '';
292291
this.toDisposeBeforeUnmount.pushAll([
293292
this.props.monitorConnection.onRead(({ data }) => {
294-
chunk += data;
295-
const eolIndex = chunk.indexOf('\n');
296-
if (eolIndex !== -1) {
297-
const line = chunk.substring(0, eolIndex + 1);
298-
chunk = chunk.slice(eolIndex + 1);
299-
const content = `${this.state.content}${this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''}${line}`;
300-
this.setState({ content });
293+
const rawLines = data.split('\n');
294+
const lines: string[] = []
295+
const timestamp = () => this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : '';
296+
for (let i = 0; i < rawLines.length; i++) {
297+
if (i === 0 && this.state.content.length !== 0) {
298+
lines.push(rawLines[i]);
299+
} else {
300+
lines.push(timestamp() + rawLines[i]);
301+
}
301302
}
303+
const content = this.state.content + lines.join('\n');
304+
this.setState({ content });
302305
}),
303306
this.props.clearConsoleEvent(() => this.setState({ content: '' })),
304307
this.props.monitorModel.onChange(({ property }) => {

0 commit comments

Comments
 (0)