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

The following examples show how to use com.intellij.execution.ui.ConsoleViewContentType#USER_INPUT . 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: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void print(@Nonnull String text, @Nonnull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) {
  text = StringUtil.convertLineSeparators(text, keepSlashR);
  synchronized (LOCK) {
    myDeferredBuffer.print(text, contentType, info);

    if (contentType == ConsoleViewContentType.USER_INPUT) {
      requestFlushImmediately();
    }
    else if (myEditor != null) {
      final boolean shouldFlushNow = myDeferredBuffer.length() >= myDeferredBuffer.getCycleBufferSize();
      addFlushRequest(shouldFlushNow ? 0 : DEFAULT_FLUSH_DELAY, FLUSH);
    }
  }
}
 
Example 2
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void sendUserInput(@Nonnull CharSequence typedText) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (myState.isRunning() && NEW_LINE_MATCHER.indexIn(typedText) >= 0) {
    StringBuilder textToSend = new StringBuilder();
    // compute text input from the console contents:
    // 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);
    }
  }
}
 
Example 3
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void type(@Nonnull Editor editor, @Nonnull String text) {
  flushDeferredText();
  SelectionModel selectionModel = editor.getSelectionModel();

  int lastOffset = selectionModel.hasSelection() ? selectionModel.getSelectionStart() : editor.getCaretModel().getOffset() - 1;
  RangeMarker marker = findTokenMarker(lastOffset);
  if (getTokenType(marker) != ConsoleViewContentType.USER_INPUT) {
    print(text, ConsoleViewContentType.USER_INPUT);
    moveScrollRemoveSelection(editor, editor.getDocument().getTextLength());
    return;
  }

  String textToUse = StringUtil.convertLineSeparators(text);
  int typeOffset;
  if (selectionModel.hasSelection()) {
    Document document = editor.getDocument();
    int start = selectionModel.getSelectionStart();
    int end = selectionModel.getSelectionEnd();
    document.deleteString(start, end);
    selectionModel.removeSelection();
    typeOffset = end;
  }
  else {
    typeOffset = selectionModel.hasSelection() ? selectionModel.getSelectionStart() : editor.getCaretModel().getOffset();
  }
  insertUserText(typeOffset, textToUse);
}
 
Example 4
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void deleteUserText(int startOffset, int length) {
  final Editor editor = myEditor;
  final Document document = editor.getDocument();

  RangeMarker marker = findTokenMarker(startOffset);
  if (getTokenType(marker) != ConsoleViewContentType.USER_INPUT) return;

  int endOffset = startOffset + length;
  if (startOffset >= 0 && endOffset >= 0 && endOffset > startOffset) {
    document.deleteString(startOffset, endOffset);
  }
  moveScrollRemoveSelection(editor, startOffset);
}