Search in sources :

Example 1 with ConsoleViewContentType

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

the class PyConsoleSourceHighlighter method next.

private Pair<String, ConsoleViewContentType> next() {
    myLexerState = myLexer.getState();
    IElementType tokenType = myLexer.getTokenType();
    Pair<String, ConsoleViewContentType> res = Pair.create(myLexer.getTokenText(), tokenType == null ? ConsoleViewContentType.NORMAL_OUTPUT : ConsoleViewUtil.getContentTypeForToken(tokenType, myPyHighlighter));
    myLexer.advance();
    return res;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 2 with ConsoleViewContentType

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

the class RemoteDebugger method writeToConsole.

private void writeToConsole(PyIo io) {
    ConsoleViewContentType contentType;
    if (io.getCtx() == 2) {
        contentType = ConsoleViewContentType.ERROR_OUTPUT;
    } else {
        contentType = ConsoleViewContentType.NORMAL_OUTPUT;
    }
    myDebugProcess.printToConsole(io.getText(), contentType);
}
Also used : ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 3 with ConsoleViewContentType

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

the class Printer method printWithAnsiColoring.

default default void printWithAnsiColoring(@NotNull String text, @NotNull Key processOutputType) {
    AnsiEscapeDecoder decoder = new AnsiEscapeDecoder();
    decoder.escapeText(text, ProcessOutputTypes.STDOUT, new AnsiEscapeDecoder.ColoredTextAcceptor() {

        @Override
        public void coloredTextAvailable(@NotNull String text, @NotNull Key attributes) {
            ConsoleViewContentType contentType = ConsoleViewContentType.getConsoleViewType(attributes);
            if (contentType == null || contentType == ConsoleViewContentType.NORMAL_OUTPUT) {
                contentType = ConsoleViewContentType.getConsoleViewType(processOutputType);
            }
            print(text, contentType);
        }
    });
}
Also used : AnsiEscapeDecoder(com.intellij.execution.process.AnsiEscapeDecoder) Key(com.intellij.openapi.util.Key) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 4 with ConsoleViewContentType

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

the class ConsoleViewImpl method flushDeferredText.

public void flushDeferredText() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (isDisposed())
        return;
    final boolean shouldStickToEnd = !myCancelStickToEnd && isStickingToEnd();
    // Cancel only needs to last for one update. Next time, isStickingToEnd() will be false.
    myCancelStickToEnd = false;
    final StringBuilder addedText;
    List<TokenBuffer.TokenInfo> deferredTokens;
    final Document document = myEditor.getDocument();
    synchronized (LOCK) {
        if (myOutputPaused)
            return;
        addedText = new StringBuilder(myDeferredBuffer.length());
        deferredTokens = myDeferredBuffer.drain();
        if (deferredTokens.isEmpty())
            return;
        cancelHeavyAlarm();
    }
    final RangeMarker lastProcessedOutput = document.createRangeMarker(document.getTextLength(), document.getTextLength());
    final Collection<ConsoleViewContentType> contentTypes = new HashSet<>();
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        if (!shouldStickToEnd) {
            myEditor.getScrollingModel().accumulateViewportChanges();
        }
        try {
            // the text can contain one "\r" at the start meaning we should delete the last line
            boolean startsWithCR = deferredTokens.get(0) == TokenBuffer.CR_TOKEN;
            int startIndex = startsWithCR ? 1 : 0;
            for (int i = startIndex; i < deferredTokens.size(); i++) {
                TokenBuffer.TokenInfo deferredToken = deferredTokens.get(i);
                addedText.append(deferredToken.getText());
            }
            if (startsWithCR) {
                // remove last line if any
                if (document.getLineCount() != 0) {
                    int lineStartOffset = document.getLineStartOffset(document.getLineCount() - 1);
                    document.deleteString(lineStartOffset, document.getTextLength());
                }
            }
            document.insertString(document.getTextLength(), addedText);
            // add token information as range markers
            // start from the end because portion of the text can be stripped from the document beginning because of a cycle buffer
            int offset = document.getTextLength();
            int tokenLength = 0;
            for (int i = deferredTokens.size() - 1; i >= startIndex; i--) {
                TokenBuffer.TokenInfo token = deferredTokens.get(i);
                contentTypes.add(token.contentType);
                tokenLength += token.length();
                TokenBuffer.TokenInfo prevToken = i == startIndex ? null : deferredTokens.get(i - 1);
                if (prevToken != null && token.contentType == prevToken.contentType && token.getHyperlinkInfo() == prevToken.getHyperlinkInfo()) {
                    // do not create highlighter yet because can merge previous token with the current
                    continue;
                }
                int start = Math.max(0, offset - tokenLength);
                if (start == offset)
                    break;
                final HyperlinkInfo info = token.getHyperlinkInfo();
                if (info != null) {
                    myHyperlinks.createHyperlink(start, offset, null, info).putUserData(MANUAL_HYPERLINK, true);
                }
                createTokenRangeHighlighter(token.contentType, start, offset);
                offset = start;
                tokenLength = 0;
            }
        } finally {
            if (!shouldStickToEnd) {
                myEditor.getScrollingModel().flushViewportChanges();
            }
        }
    }, null, DocCommandGroupId.noneGroupId(document));
    if (!contentTypes.isEmpty()) {
        for (ChangeListener each : myListeners) {
            each.contentAdded(contentTypes);
        }
    }
    myPsiDisposedCheck.performCheck();
    int startLine = lastProcessedOutput.isValid() ? myEditor.getDocument().getLineNumber(lastProcessedOutput.getEndOffset()) : 0;
    lastProcessedOutput.dispose();
    highlightHyperlinksAndFoldings(startLine);
    if (shouldStickToEnd) {
        scrollToEnd();
    }
    sendUserInput(addedText);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) THashSet(gnu.trove.THashSet) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 5 with ConsoleViewContentType

use of com.intellij.execution.ui.ConsoleViewContentType in project intellij-plugins by JetBrains.

the class KarmaServerLogComponent method register.

public static void register(@NotNull Project project, @NotNull final KarmaServer server, @NotNull final RunnerLayoutUi ui, boolean requestFocus) {
    final ConsoleView console = createConsole(project);
    KarmaServerLogComponent component = new KarmaServerLogComponent(console, server);
    final Content content = ui.createContent("KarmaServer", component, "Karma Server", null, console.getPreferredFocusableComponent());
    content.setCloseable(false);
    ui.addContent(content, 4, PlaceInGrid.bottom, false);
    if (requestFocus && !server.isPortBound()) {
        ui.selectAndFocus(content, false, false);
    }
    final KarmaServerTerminatedListener terminationCallback = new KarmaServerTerminatedListener() {

        @Override
        public void onTerminated(int exitCode) {
            KarmaUtil.selectAndFocusIfNotDisposed(ui, content, false, false);
        }
    };
    server.onTerminated(terminationCallback);
    final ArchivedOutputListener outputListener = new ArchivedOutputListener() {

        @Override
        public void onOutputAvailable(@NotNull String text, Key outputType, boolean archived) {
            ConsoleViewContentType contentType = ConsoleViewContentType.getConsoleViewType(outputType);
            console.print(text, contentType);
            if (!archived && text.startsWith("ERROR ")) {
                ApplicationManager.getApplication().invokeLater(() -> content.fireAlert(), ModalityState.any());
            }
        }
    };
    server.getProcessOutputManager().addOutputListener(outputListener);
    Disposer.register(content, console);
    Disposer.register(console, new Disposable() {

        @Override
        public void dispose() {
            server.removeTerminatedListener(terminationCallback);
            server.getProcessOutputManager().removeOutputListener(outputListener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) ConsoleView(com.intellij.execution.ui.ConsoleView) Content(com.intellij.ui.content.Content) ArchivedOutputListener(com.intellij.javascript.karma.util.ArchivedOutputListener) NotNull(org.jetbrains.annotations.NotNull) Key(com.intellij.openapi.util.Key) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Aggregations

ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)14 Key (com.intellij.openapi.util.Key)5 AnsiEscapeDecoder (com.intellij.execution.process.AnsiEscapeDecoder)2 ConsoleView (com.intellij.execution.ui.ConsoleView)2 IElementType (com.intellij.psi.tree.IElementType)2 Content (com.intellij.ui.content.Content)2 JsonObject (com.google.gson.JsonObject)1 JstdServerOutputListener (com.google.jstestdriver.idea.server.JstdServerOutputListener)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 Printable (com.intellij.execution.testframework.Printable)1 Printer (com.intellij.execution.testframework.Printer)1 ArchivedOutputListener (com.intellij.javascript.karma.util.ArchivedOutputListener)1 FlexUnitRunnerParameters (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters)1 Lexer (com.intellij.lexer.Lexer)1 Disposable (com.intellij.openapi.Disposable)1 ActionToolbar (com.intellij.openapi.actionSystem.ActionToolbar)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 StringTokenizer (com.intellij.util.text.StringTokenizer)1 THashSet (gnu.trove.THashSet)1