Cut out escapes from vagrant output in message dialogs.

This commit is contained in:
Dmitry Trofimov
2014-01-04 23:13:51 +01:00
parent baef75755d
commit 2989162d2b
4 changed files with 80 additions and 6 deletions
@@ -84,7 +84,7 @@ public class AnsiEscapeDecoder {
return endMacroPos;
}
private Key getCurrentOutputAttributes(final Key outputType) {
protected Key getCurrentOutputAttributes(final Key outputType) {
if (outputType == ProcessOutputTypes.STDERR || outputType == ProcessOutputTypes.SYSTEM) {
return outputType;
}
@@ -0,0 +1,66 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.process;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.NotNull;
/**
* Capturing process handler that cuts off ansi escapes
*
* @author traff
*/
public class CapturingAnsiEscapesAwareProcessHandler extends CapturingProcessHandler {
public CapturingAnsiEscapesAwareProcessHandler(@NotNull GeneralCommandLine commandLine)
throws ExecutionException {
super(commandLine);
}
public CapturingAnsiEscapesAwareProcessHandler(Process process) {
super(process);
}
@Override
protected CapturingProcessAdapter createProcessAdapter(ProcessOutput processOutput) {
return new AnsiEscapesAwareAdapter(processOutput);
}
private static class AnsiEscapesAwareAdapter extends CapturingProcessAdapter implements AnsiEscapeDecoder.ColoredTextAcceptor {
private final AnsiEscapeDecoder myAnsiEscapeDecoder = new AnsiEscapeDecoder() {
@Override
protected Key getCurrentOutputAttributes(Key outputType) {
return outputType; //we don't need color information - only stdout and stderr keys are added to output in CapturingProcessAdapter
}
};
public AnsiEscapesAwareAdapter(ProcessOutput output) {
super(output);
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
myAnsiEscapeDecoder.escapeText(event.getText(), outputType, this);
}
@Override
public void coloredTextAvailable(String text, Key attributes) {
addToOutput(text, attributes);
}
}
}
@@ -34,11 +34,15 @@ public class CapturingProcessAdapter extends ProcessAdapter {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
addToOutput(event.getText(), outputType);
}
protected void addToOutput(String text, Key outputType) {
if (outputType == ProcessOutputTypes.STDOUT) {
myOutput.appendStdout(event.getText());
myOutput.appendStdout(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
myOutput.appendStderr(event.getText());
myOutput.appendStderr(text);
}
}
@@ -30,10 +30,10 @@ import java.nio.charset.Charset;
public class CapturingProcessHandler extends OSProcessHandler {
private static final Logger LOG = Logger.getInstance(CapturingProcessHandler.class);
private final ProcessOutput myOutput = new ProcessOutput();
public CapturingProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
super(commandLine);
addProcessListener(new CapturingProcessAdapter(myOutput));
addProcessListener(createProcessAdapter(myOutput));
}
public CapturingProcessHandler(final Process process) {
@@ -46,9 +46,13 @@ public class CapturingProcessHandler extends OSProcessHandler {
public CapturingProcessHandler(final Process process, final Charset charset, final String commandLine) {
super(process, commandLine, charset);
addProcessListener(new CapturingProcessAdapter(myOutput));
addProcessListener(createProcessAdapter(myOutput));
}
protected CapturingProcessAdapter createProcessAdapter(ProcessOutput processOutput) {
return new CapturingProcessAdapter(processOutput);
}
public ProcessOutput runProcess() {
startNotify();
if (waitFor()) {