Search in sources :

Example 36 with ConsoleView

use of com.intellij.execution.ui.ConsoleView in project intellij-community by JetBrains.

the class LogConsoleBase method printMessageToConsole.

private int printMessageToConsole(String line) {
    final ConsoleView console = getConsoleNotNull();
    if (myContentPreprocessor != null) {
        List<LogFragment> fragments = myContentPreprocessor.parseLogLine(line + '\n');
        for (LogFragment fragment : fragments) {
            ConsoleViewContentType consoleViewType = ConsoleViewContentType.getConsoleViewType(fragment.getOutputType());
            if (consoleViewType != null) {
                String formattedText = myFormatter.formatMessage(fragment.getText());
                console.print(formattedText, consoleViewType);
            }
        }
        return line.length() + 1;
    } else {
        final LogFilterModel.MyProcessingResult processingResult = myModel.processLine(line);
        if (processingResult.isApplicable()) {
            final Key key = processingResult.getKey();
            if (key != null) {
                ConsoleViewContentType type = ConsoleViewContentType.getConsoleViewType(key);
                if (type != null) {
                    final String messagePrefix = processingResult.getMessagePrefix();
                    if (messagePrefix != null) {
                        String formattedPrefix = myFormatter.formatPrefix(messagePrefix);
                        console.print(formattedPrefix, type);
                    }
                    String formattedMessage = myFormatter.formatMessage(line);
                    console.print(formattedMessage + "\n", type);
                    return (messagePrefix != null ? messagePrefix.length() : 0) + line.length() + 1;
                }
            }
        }
        return 0;
    }
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) Key(com.intellij.openapi.util.Key) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 37 with ConsoleView

use of com.intellij.execution.ui.ConsoleView in project intellij-community by JetBrains.

the class EOFAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
    ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
    if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated())
        return;
    try {
        OutputStream input = activeProcessHandler.getProcessInput();
        if (input != null) {
            ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
            if (console != null) {
                console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
            }
            input.close();
        }
    } catch (IOException ignored) {
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleView(com.intellij.execution.ui.ConsoleView) OutputStream(java.io.OutputStream) ProcessHandler(com.intellij.execution.process.ProcessHandler) IOException(java.io.IOException)

Example 38 with ConsoleView

use of com.intellij.execution.ui.ConsoleView in project intellij-community by JetBrains.

the class PythonCommandLineState method createAndAttachConsole.

@NotNull
protected ConsoleView createAndAttachConsole(Project project, ProcessHandler processHandler, Executor executor) throws ExecutionException {
    final ConsoleView consoleView = createConsoleBuilder(project).getConsole();
    consoleView.addMessageFilter(createUrlFilter(processHandler));
    addTracebackFilter(project, consoleView, processHandler);
    consoleView.attachToProcess(processHandler);
    return consoleView;
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with ConsoleView

use of com.intellij.execution.ui.ConsoleView in project intellij-community by JetBrains.

the class PyUnitTestTask method getHighlightedStrings.

/**
   * Gets highlighted information from test console. Some parts of output (like file links) may be highlighted, and you need to check them.
   *
   * @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and "text" is text extracted from this region.
   * For example assume that in document "spam eggs ham" words "ham" and "spam" are highlighted.
   * You should have 2 ranges (0, 4) and (10, 13) and 2 strings (spam and ham)
   */
@NotNull
public final Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStrings() {
    final ConsoleView console = myConsoleView.getConsole();
    assert console instanceof ConsoleViewImpl : "Console has no editor!";
    final ConsoleViewImpl consoleView = (ConsoleViewImpl) console;
    final Editor editor = consoleView.getEditor();
    final List<String> resultStrings = new ArrayList<>();
    final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            /**
         * To fetch data from console we need to flush it first.
         * It works locally, but does not work on TC (reasons are not clear yet and need to be investigated).
         * So, we flush it explicitly to make test run on TC.
         */
            consoleView.flushDeferredText();
            for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
                if (highlighter instanceof RangeHighlighterEx) {
                    final int start = ((RangeHighlighterEx) highlighter).getAffectedAreaStartOffset();
                    final int end = ((RangeHighlighterEx) highlighter).getAffectedAreaEndOffset();
                    resultRanges.add(Pair.create(start, end));
                    resultStrings.add(editor.getDocument().getText().substring(start, end));
                }
            }
        }
    });
    final String message = String.format("Following output is searched for hightlighed strings: %s \n", editor.getDocument().getText());
    Logger.getInstance(getClass()).warn(message);
    return Pair.create(resultRanges, resultStrings);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) ConsoleView(com.intellij.execution.ui.ConsoleView) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with ConsoleView

use of com.intellij.execution.ui.ConsoleView in project intellij-community by JetBrains.

the class PyTestCommandLineState method createAndAttachConsole.

@NotNull
protected ConsoleView createAndAttachConsole(Project project, ProcessHandler processHandler, Executor executor) throws ExecutionException {
    final ConsoleView consoleView = super.createAndAttachConsole(project, processHandler, executor);
    addTracebackFilter(project, consoleView, processHandler);
    return consoleView;
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ConsoleView (com.intellij.execution.ui.ConsoleView)43 NotNull (org.jetbrains.annotations.NotNull)21 ProcessHandler (com.intellij.execution.process.ProcessHandler)16 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)10 SMTRunnerConsoleView (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)8 TextConsoleBuilder (com.intellij.execution.filters.TextConsoleBuilder)6 Content (com.intellij.ui.content.Content)6 ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)5 ToolWindow (com.intellij.openapi.wm.ToolWindow)5 Executor (com.intellij.execution.Executor)4 TestConsoleProperties (com.intellij.execution.testframework.TestConsoleProperties)4 ToggleAutoTestAction (com.intellij.execution.testframework.autotest.ToggleAutoTestAction)4 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)4 Disposable (com.intellij.openapi.Disposable)4 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)3 AbstractRerunFailedTestsAction (com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction)3 BaseTestsOutputConsoleView (com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView)3 CloseAction (com.intellij.execution.ui.actions.CloseAction)3 Project (com.intellij.openapi.project.Project)3 AndroidLogcatView (com.android.tools.idea.logcat.AndroidLogcatView)2