From 5c16f8d6c91f3dba9dfe4cca1d7d2dfa0d5b67c4 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 2 Mar 2020 14:46:40 +0100 Subject: [PATCH] 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 --- .../src/browser/monitor/monitor-widget.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx index 42f454f3..c5b81873 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx @@ -288,17 +288,20 @@ export class SerialMonitorOutput extends React.Component { - chunk += data; - const eolIndex = chunk.indexOf('\n'); - if (eolIndex !== -1) { - const line = chunk.substring(0, eolIndex + 1); - chunk = chunk.slice(eolIndex + 1); - const content = `${this.state.content}${this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''}${line}`; - this.setState({ content }); + const rawLines = data.split('\n'); + const lines: string[] = [] + const timestamp = () => this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''; + for (let i = 0; i < rawLines.length; i++) { + if (i === 0 && this.state.content.length !== 0) { + lines.push(rawLines[i]); + } else { + lines.push(timestamp() + rawLines[i]); + } } + const content = this.state.content + lines.join('\n'); + this.setState({ content }); }), this.props.clearConsoleEvent(() => this.setState({ content: '' })), this.props.monitorModel.onChange(({ property }) => {