Java Code Examples for com.intellij.execution.ui.ConsoleViewContentType#NORMAL_OUTPUT_KEY

The following examples show how to use com.intellij.execution.ui.ConsoleViewContentType#NORMAL_OUTPUT_KEY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleLogConsole.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
void doPrintNotification(final Notification notification) {
    Editor editor = myLogEditor.getValue();
    if (editor.isDisposed()) {
        return;
    }

    Document document = editor.getDocument();
    boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();

    Long notificationTime = myProjectModel.getNotificationTime(notification);
    if (notificationTime == null) {
        return;
    }

    String date = DateFormatUtil.formatTimeWithSeconds(notificationTime) + " ";
    append(document, date);

    int startLine = document.getLineCount() - 1;

    ConsoleLog.LogEntry pair = ConsoleLog.formatForLog(notification, StringUtil.repeatSymbol(' ', date.length()));

    final NotificationType type = notification.getType();
    TextAttributesKey key = type == NotificationType.ERROR
        ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY
        : type == NotificationType.INFORMATION
        ? ConsoleViewContentType.NORMAL_OUTPUT_KEY
        : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;

    int msgStart = document.getTextLength();
    String message = pair.message;
    append(document, message);

    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
    int layer = HighlighterLayer.CARET_ROW + 1;
    editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);

    for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
        final RangeHighlighter rangeHighlighter = myHyperlinkSupport.getValue()
            .createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
        if (link.second instanceof ConsoleLog.ShowBalloon) {
            ((ConsoleLog.ShowBalloon)link.second).setRangeHighlighter(rangeHighlighter);
        }
    }

    append(document, "\n");

    if (scroll) {
        editor.getCaretModel().moveToOffset(document.getTextLength());
        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }

    if (notification.isImportant()) {
        highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1);
    }
}
 
Example 2
Source File: ColoredOutputTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static TextAttributesKey getAnsiColorKey(int value) {
  if (value >= 16) {
    return ConsoleViewContentType.NORMAL_OUTPUT_KEY;
  }
  return myAnsiColorKeys[value];
}
 
Example 3
Source File: EventLogConsole.java    From consulo with Apache License 2.0 4 votes vote down vote up
void doPrintNotification(final Notification notification) {
  Editor editor = getConsoleEditor();
  if (editor.isDisposed()) {
    return;
  }

  Document document = editor.getDocument();
  boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();

  if (document.getTextLength() > 0) {
    append(document, "\n");
  }

  String lastDate = DateFormatUtil.formatDate(notification.getTimestamp());
  if (document.getTextLength() == 0 || !lastDate.equals(myLastDate)) {
    myLastDate = lastDate;
    append(document, lastDate + "\n");
  }

  int startDateOffset = document.getTextLength();

  String date = DateFormatUtil.formatTime(notification.getTimestamp()) + "\t";
  append(document, date);

  int tabs = calculateTabs(editor, startDateOffset);

  int titleStartOffset = document.getTextLength();
  int startLine = document.getLineCount() - 1;

  EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol('\t', tabs));

  final NotificationType type = notification.getType();
  TextAttributesKey key = type == NotificationType.ERROR
                          ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY
                          : type == NotificationType.INFORMATION ? ConsoleViewContentType.NORMAL_OUTPUT_KEY : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;

  int msgStart = document.getTextLength();
  append(document, pair.message);

  TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
  int layer = HighlighterLayer.CARET_ROW + 1;
  RangeHighlighter highlighter =
          editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);
  GROUP_ID.set(highlighter, notification.getGroupId());
  NOTIFICATION_ID.set(highlighter, notification.id);

  for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
    final RangeHighlighter rangeHighlighter =
            myHyperlinkSupport.getValue().createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
    if (link.second instanceof EventLog.ShowBalloon) {
      ((EventLog.ShowBalloon)link.second).setRangeHighlighter(rangeHighlighter);
    }
  }

  append(document, "\n");

  if (scroll) {
    editor.getCaretModel().moveToOffset(document.getTextLength());
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  }

  if (notification.isImportant()) {
    highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1, titleStartOffset, pair.titleLength);
  }
}