fix(serial-monitor): strip ANSI escape sequences from board output

Beta testers saw raw `[0;32m` and `[0m` text mixed into the serial
monitor for several ESP32 examples. Those are ANSI SGR escapes the
ESP-IDF logger emits to color INFO/WARN lines on a real terminal. Our
<pre> renders them literally because there was no ANSI handling in
the path.

Strip the SGR sequences (`\x1b\[[0-9;]*m`) before the IP-linkifier so
the user only sees plain text. Combined with the sdkconfig change that
drops the default log level to WARN, the ESP32 output is now as clean
as the AVR output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Montero Crespo 2026-05-08 16:32:59 -03:00
parent f6f6f43cc2
commit bba935f93d
1 changed files with 6 additions and 1 deletions

View File

@ -247,7 +247,12 @@ export const SerialMonitor: React.FC = () => {
<pre ref={outputRef} style={styles.output}> <pre ref={outputRef} style={styles.output}>
{activeBoard?.serialOutput {activeBoard?.serialOutput
? (() => { ? (() => {
const text = activeBoard.serialOutput; // ESP-IDF and many other firmwares emit ANSI SGR escapes
// (`\x1b[0;32m...`). The <pre> renders them literally, so
// users saw raw `[0;32m` mixed into their Serial.print output.
// Strip them before any further processing — color isn't
// worth a full parser here.
const text = activeBoard.serialOutput.replace(/\x1b\[[0-9;]*m/g, '');
const ipRegex = /http:\/\/192\.168\.4\.(\d+)(\/[^\s]*)?/g; const ipRegex = /http:\/\/192\.168\.4\.(\d+)(\/[^\s]*)?/g;
const matches = [...text.matchAll(ipRegex)]; const matches = [...text.matchAll(ipRegex)];