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);
}
});
}
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);
}
}
}
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;
}
}
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);
}
});
}
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();
}
}
Aggregations