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