From 1981d5905d23e714eaf4be8d9bf5b5fd050b1c64 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sun, 26 Mar 2017 15:39:10 -0400 Subject: [PATCH] Remove ANSI escape sequences from lines before handing them to output parsers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a build tool (e.g. gcc) outputs colored text, the ANSI escape sequences will prevent the output parsers from matching the lines. This patch makes the ErrorParserManager remove them before handing the strings to the parsers. I tested that this works well with the ANSI console plugin [1], which allows displaying colors in the console window. Note that I stole the regex from this SO post [2], I hope it's trivial enough that it doesn't cause any IP problem. [1] https://marketplace.eclipse.org/content/ansi-escape-console [2] https://stackoverflow.com/questions/25189651/how-to-remove-ansi-control-chars-vt100-from-a-java-string Change-Id: I0d6a25723be4008600acecb8595865bcb4f4abc1 Signed-off-by: Simon Marchi --- .../src/org/eclipse/cdt/core/ErrorParserManager.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java index 52974fdab1b..8a0c7cc465c 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Vector; +import java.util.regex.Pattern; import org.eclipse.cdt.core.errorparsers.ErrorParserNamedWrapper; import org.eclipse.cdt.core.language.settings.providers.IWorkingDirectoryTracker; @@ -74,6 +75,8 @@ public class ErrorParserManager extends OutputStream implements IConsoleParser, */ public static final String BUILD_CONTEXT = "build"; //$NON-NLS-1$ + private static final Pattern ANSI_ESCAPE_RE = Pattern.compile("\\e\\[[\\d;]*[^\\d;]"); //$NON-NLS-1$ + private int nOpens; private int lineCounter=0; @@ -317,7 +320,11 @@ public class ErrorParserManager extends OutputStream implements IConsoleParser, */ @Override public boolean processLine(String line) { - String lineTrimmed = line.trim(); + /* + * If the tool outputs colored text, it will contain ANSI escape + * sequences. Remove them, since they can confuse the error parsers. + */ + String lineTrimmed = ANSI_ESCAPE_RE.matcher(line).replaceAll("").trim(); //$NON-NLS-1$ lineCounter++; ProblemMarkerInfo marker=null;