Search in sources :

Example 6 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)

Example 7 with ConsoleViewContentType

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

the class ConsoleViewImpl method sendUserInput.

private void sendUserInput(@NotNull CharSequence typedText) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myState.isRunning() && NEW_LINE_MATCHER.indexIn(typedText) >= 0) {
        StringBuilder textToSend = new StringBuilder();
        // all range markers beginning from the caret offset backwards, marked as user input and not marked as already sent
        for (RangeMarker marker = findTokenMarker(myEditor.getCaretModel().getOffset() - 1); marker != null; marker = ((RangeMarkerImpl) marker).findRangeMarkerBefore()) {
            ConsoleViewContentType tokenType = getTokenType(marker);
            if (tokenType != null) {
                if (tokenType != ConsoleViewContentType.USER_INPUT || marker.getUserData(USER_INPUT_SENT) == Boolean.TRUE) {
                    break;
                }
                marker.putUserData(USER_INPUT_SENT, true);
                textToSend.insert(0, marker.getDocument().getText(TextRange.create(marker)));
            }
        }
        if (textToSend.length() != 0) {
            myFlushUserInputAlarm.addRequest(() -> {
                if (myState.isRunning()) {
                    try {
                        // this may block forever, see IDEA-54340
                        myState.sendUserInput(textToSend.toString());
                    } catch (IOException ignored) {
                    }
                }
            }, 0);
        }
    }
}
Also used : IOException(java.io.IOException) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Example 8 with ConsoleViewContentType

use of com.intellij.execution.ui.ConsoleViewContentType 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 9 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 ConsoleViewContentType contentType) {
    AnsiEscapeDecoder decoder = new AnsiEscapeDecoder();
    decoder.escapeText(text, ProcessOutputTypes.STDOUT, new AnsiEscapeDecoder.ColoredTextAcceptor() {

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

Example 10 with ConsoleViewContentType

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

the class ConsoleViewUtil method printWithHighlighting.

public static void printWithHighlighting(@NotNull ConsoleView console, @NotNull String text, @NotNull SyntaxHighlighter highlighter, Runnable doOnNewLine) {
    Lexer lexer = highlighter.getHighlightingLexer();
    lexer.start(text, 0, text.length(), 0);
    IElementType tokenType;
    while ((tokenType = lexer.getTokenType()) != null) {
        ConsoleViewContentType contentType = getContentTypeForToken(tokenType, highlighter);
        StringTokenizer eolTokenizer = new StringTokenizer(lexer.getTokenText(), "\n", true);
        while (eolTokenizer.hasMoreTokens()) {
            String tok = eolTokenizer.nextToken();
            console.print(tok, contentType);
            if (doOnNewLine != null && "\n".equals(tok)) {
                doOnNewLine.run();
            }
        }
        lexer.advance();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Lexer(com.intellij.lexer.Lexer) StringTokenizer(com.intellij.util.text.StringTokenizer) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType)

Aggregations

ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)13 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