当前位置: 首页>>代码示例>>Java>>正文


Java ConsoleViewContentType.USER_INPUT属性代码示例

本文整理汇总了Java中com.intellij.execution.ui.ConsoleViewContentType.USER_INPUT属性的典型用法代码示例。如果您正苦于以下问题:Java ConsoleViewContentType.USER_INPUT属性的具体用法?Java ConsoleViewContentType.USER_INPUT怎么用?Java ConsoleViewContentType.USER_INPUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.intellij.execution.ui.ConsoleViewContentType的用法示例。


在下文中一共展示了ConsoleViewContentType.USER_INPUT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printHyperlink

private void printHyperlink(@NotNull String s, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) {
  synchronized (LOCK) {
    Pair<String, Integer> pair = myBuffer.print(s, contentType, info);
    s = pair.first;
    myContentSize += s.length() - pair.second;

    if (contentType == ConsoleViewContentType.USER_INPUT && NEW_LINE_MATCHER.indexIn(s) >= 0) {
      flushDeferredUserInput();
    }
    if (myEditor != null && !myFlushAlarm.isDisposed()) {
      final boolean shouldFlushNow = myBuffer.isUseCyclicBuffer() && myBuffer.getLength() >= myBuffer.getCyclicBufferSize();
      addFlushRequest(new MyFlushRunnable(), shouldFlushNow ? 0 : DEFAULT_FLUSH_DELAY);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ConsoleViewImpl.java

示例2: insertUserText

/**
 * insert text to document
 *
 * @param s      inserted text
 * @param offset relatively to all document text
 */
private void insertUserText(final String s, int offset) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  final ConsoleViewImpl consoleView = this;
  final ConsoleBuffer buffer = consoleView.myBuffer;
  final Editor editor = consoleView.myEditor;
  final Document document = editor.getDocument();
  final int startOffset;

  String textToUse = StringUtil.convertLineSeparators(s);
  synchronized (consoleView.LOCK) {
    if (consoleView.myTokens.isEmpty()) {
      addToken(0, null, ConsoleViewContentType.SYSTEM_OUTPUT);
    }
    final TokenInfo info = consoleView.myTokens.get(consoleView.myTokens.size() - 1);
    if (info.contentType != ConsoleViewContentType.USER_INPUT && !StringUtil.containsChar(textToUse, '\n')) {
      consoleView.print(textToUse, ConsoleViewContentType.USER_INPUT);
      consoleView.flushDeferredText();
      editor.getCaretModel().moveToOffset(document.getTextLength());
      editor.getSelectionModel().removeSelection();
      return;
    }
    if (info.contentType != ConsoleViewContentType.USER_INPUT) {
      insertUserText("temp", offset);
      final TokenInfo newInfo = consoleView.myTokens.get(consoleView.myTokens.size() - 1);
      replaceUserText(textToUse, newInfo.startOffset, newInfo.endOffset);
      return;
    }

    final int deferredOffset = myContentSize - buffer.getLength() - buffer.getUserInputLength();
    if (offset > info.endOffset) {
      startOffset = info.endOffset;
    }
    else {
      startOffset = Math.max(deferredOffset, Math.max(info.startOffset, offset));
    }

    buffer.addUserText(startOffset - deferredOffset, textToUse);

    int charCountToAdd = textToUse.length();
    info.endOffset += charCountToAdd;
    consoleView.myContentSize += charCountToAdd;
  }

  try {
    myInDocumentUpdate = true;
    document.insertString(startOffset, textToUse);
  }
  finally {
    myInDocumentUpdate = false;
  }
  // Math.max is needed when cyclic buffer is used
  editor.getCaretModel().moveToOffset(Math.min(startOffset + textToUse.length(), document.getTextLength()));
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:ConsoleViewImpl.java

示例3: replaceUserText

/**
 * replace text
 *
 * @param s     text for replace
 * @param start relatively to all document text
 * @param end   relatively to all document text
 */
private void replaceUserText(final String s, int start, int end) {
  if (start == end) {
    insertUserText(s, start);
    return;
  }
  final ConsoleViewImpl consoleView = this;
  final ConsoleBuffer buffer = consoleView.myBuffer;
  final Editor editor = consoleView.myEditor;
  final Document document = editor.getDocument();
  final int startOffset;
  final int endOffset;

  synchronized (consoleView.LOCK) {
    if (consoleView.myTokens.isEmpty()) return;
    final TokenInfo info = consoleView.myTokens.get(consoleView.myTokens.size() - 1);
    if (info.contentType != ConsoleViewContentType.USER_INPUT) {
      consoleView.print(s, ConsoleViewContentType.USER_INPUT);
      consoleView.flushDeferredText();
      editor.getCaretModel().moveToOffset(document.getTextLength());
      editor.getSelectionModel().removeSelection();
      return;
    }
    if (buffer.getUserInputLength() <= 0) return;

    final int deferredOffset = myContentSize - buffer.getLength() - buffer.getUserInputLength();

    startOffset = getStartOffset(start, info, deferredOffset);
    endOffset = getEndOffset(end, info);

    if (startOffset == -1 ||
        endOffset == -1 ||
        endOffset <= startOffset) {
      editor.getSelectionModel().removeSelection();
      editor.getCaretModel().moveToOffset(start);
      return;
    }
    int charCountToReplace = s.length() - endOffset + startOffset;

    buffer.replaceUserText(startOffset - deferredOffset, endOffset - deferredOffset, s);

    info.endOffset += charCountToReplace;
    if (info.startOffset == info.endOffset) {
      consoleView.myTokens.remove(consoleView.myTokens.size() - 1);
    }
    consoleView.myContentSize += charCountToReplace;
  }

  try {
    myInDocumentUpdate = true;
    document.replaceString(startOffset, endOffset, s);
  }
  finally {
    myInDocumentUpdate = false;
  }
  editor.getCaretModel().moveToOffset(startOffset + s.length());
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:ConsoleViewImpl.java

示例4: deleteUserText

/**
 * delete text
 *
 * @param offset relatively to all document text
 * @param length length of deleted text
 */
private void deleteUserText(int offset, int length) {
  ConsoleViewImpl consoleView = this;
  ConsoleBuffer buffer = consoleView.myBuffer;
  final Editor editor = consoleView.myEditor;
  final Document document = editor.getDocument();
  final int startOffset;
  final int endOffset;

  synchronized (consoleView.LOCK) {
    if (consoleView.myTokens.isEmpty()) return;
    final TokenInfo info = consoleView.myTokens.get(consoleView.myTokens.size() - 1);
    if (info.contentType != ConsoleViewContentType.USER_INPUT) return;
    if (myBuffer.getUserInputLength() == 0) return;

    final int deferredOffset = myContentSize - buffer.getLength() - buffer.getUserInputLength();
    startOffset = getStartOffset(offset, info, deferredOffset);
    endOffset = getEndOffset(offset + length, info);
    if (startOffset == -1 ||
        endOffset == -1 ||
        endOffset <= startOffset ||
        startOffset < deferredOffset) {
      editor.getSelectionModel().removeSelection();
      editor.getCaretModel().moveToOffset(offset);
      return;
    }

    buffer.removeUserText(startOffset - deferredOffset, endOffset - deferredOffset);
  }

  try {
    myInDocumentUpdate = true;
    document.deleteString(startOffset, endOffset);
  }
  finally {
    myInDocumentUpdate = false;
  }
  editor.getCaretModel().moveToOffset(startOffset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:46,代码来源:ConsoleViewImpl.java

示例5: print

/**
 * Asks current buffer to store given text of the given type.
 *
 * @param s           text to store
 * @param contentType type of the given text
 * @param info        hyperlink info for the given text (if any)
 * @return text that is actually stored (there is a possible case that the buffer is full and given text's type
 *         is considered to have lower priority than the stored one, hence, it's better to drop given text completely
 *         or partially) and number of existed symbols removed during storing the given data
 */
@NotNull
public Pair<String, Integer> print(@NotNull String s, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) {
  int numberOfSymbolsToProceed = s.length();
  int trimmedSymbolsNumber = myDeferredOutputLength;
  if (contentType != ConsoleViewContentType.USER_INPUT) {
    numberOfSymbolsToProceed = trimDeferredOutputIfNecessary(s.length());
    trimmedSymbolsNumber -= myDeferredOutputLength;
  }
  else {
    trimmedSymbolsNumber = 0;
  }

  if (numberOfSymbolsToProceed <= 0) {
    return new Pair<String, Integer>("", 0);
  }

  if (numberOfSymbolsToProceed < s.length()) {
    s = s.substring(s.length() - numberOfSymbolsToProceed);
  }

  myDeferredTypes.add(contentType);

  s = StringUtil.convertLineSeparators(s, true);

  myDeferredOutputLength += s.length();
  StringBuilder bufferToUse;
  if (myDeferredOutput.isEmpty()) {
    myDeferredOutput.add(bufferToUse = new StringBuilder(myCyclicBufferUnitSize));
  }
  else {
    bufferToUse = myDeferredOutput.getLast();
  }
  int offset = 0;
  while (offset < s.length()) {
    if (bufferToUse.length() >= myCyclicBufferUnitSize) {
      myDeferredOutput.add(bufferToUse = new StringBuilder(myCyclicBufferUnitSize));
    }

    if (bufferToUse.length() < myCyclicBufferUnitSize) {
      int numberOfSymbolsToAdd = Math.min(myCyclicBufferUnitSize - bufferToUse.length(), s.length() - offset);
      bufferToUse.append(s.substring(offset, offset + numberOfSymbolsToAdd));
      offset += numberOfSymbolsToAdd;
    }
  }

  if (contentType == ConsoleViewContentType.USER_INPUT) {
    myDeferredUserInput.append(s);
  }

  ConsoleUtil.addToken(s.length(), info, contentType, myDeferredTokens);
  return new Pair<String, Integer>(s, trimmedSymbolsNumber);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:62,代码来源:ConsoleBuffer.java


注:本文中的com.intellij.execution.ui.ConsoleViewContentType.USER_INPUT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。