com.intellij.execution.impl.ConsoleViewImpl Java Examples

The following examples show how to use com.intellij.execution.impl.ConsoleViewImpl. 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: PromptConsole.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
PromptConsole(@NotNull Project project, ConsoleViewImpl consoleView) {
    m_consoleView = consoleView;

    EditorFactory editorFactory = EditorFactory.getInstance();
    PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);

    Document outputDocument = ((EditorFactoryImpl) editorFactory).createDocument(true);
    UndoUtil.disableUndoFor(outputDocument);
    m_outputEditor = (EditorImpl) editorFactory.createViewer(outputDocument, project, CONSOLE);

    PsiFile file = fileFactory.createFileFromText("PromptConsoleDocument.ml", OclLanguage.INSTANCE, "");
    Document promptDocument = file.getViewProvider().getDocument();
    m_promptEditor = (EditorImpl) editorFactory.createEditor(promptDocument, project, CONSOLE);

    setupOutputEditor();
    setupPromptEditor();

    m_consoleView.print("(* ctrl+enter to send a command, ctrl+up/down to cycle through history *)\r\n", USER_INPUT);

    m_mainPanel.add(m_outputEditor.getComponent(), BorderLayout.CENTER);
    m_mainPanel.add(m_promptEditor.getComponent(), BorderLayout.SOUTH);
}
 
Example #2
Source File: AnalyzeStacktraceUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static RunContentDescriptor addConsole(Project project, @Nullable ConsoleFactory consoleFactory, final String tabTitle, String text, @Nullable consulo.ui.image.Image icon) {
  final TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
  builder.filters(EP_NAME.getExtensions(project));
  final ConsoleView consoleView = builder.getConsole();

  final DefaultActionGroup toolbarActions = new DefaultActionGroup();
  JComponent consoleComponent = consoleFactory != null ? consoleFactory.createConsoleComponent(consoleView, toolbarActions) : new MyConsolePanel(consoleView, toolbarActions);
  final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, null, consoleComponent, tabTitle, icon) {
    @Override
    public boolean isContentReuseProhibited() {
      return true;
    }
  };

  final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  for (AnAction action : consoleView.createConsoleActions()) {
    toolbarActions.add(action);
  }
  final ConsoleViewImpl console = (ConsoleViewImpl)consoleView;
  ConsoleViewUtil.enableReplaceActionForConsoleViewEditor(console.getEditor());
  console.getEditor().getSettings().setCaretRowShown(true);
  toolbarActions.add(new AnnotateStackTraceAction(console.getEditor(), console.getHyperlinks()));
  ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);
  consoleView.allowHeavyFilters();
  if (consoleFactory == null) {
    printStacktrace(consoleView, text);
  }
  return descriptor;
}
 
Example #3
Source File: LogView.java    From logviewer with Apache License 2.0 6 votes vote down vote up
/**
 * Filters the console
 */
private synchronized void doFilter(ProgressIndicator progressIndicator) {
    final ConsoleView console = getConsole();
    String allLInes = getOriginalDocument().toString();
    final String[] lines = allLInes.split("\n");
    if (console != null) {
        console.clear();
    }
    myLogFilterModel.processingStarted();
    int size = lines.length;
    float current = 0;
    for (String line : lines) {
        printMessageToConsole(line);
        current++;
        progressIndicator.setFraction(current / size);
    }
    if (console != null) {
        ((ConsoleViewImpl) console).requestScrollingToEnd();
    }
}
 
Example #4
Source File: DuplexConsoleView.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private List<AnAction> mergeConsoleActions(@Nonnull List<AnAction> actions1, @Nonnull Collection<AnAction> actions2) {
  return ContainerUtil.map(actions1, action1 -> {
    final AnAction action2 = ContainerUtil.find(actions2, action -> action1.getClass() == action.getClass() &&
                                                                    StringUtil.equals(action1.getTemplatePresentation().getText(),
                                                                                      action.getTemplatePresentation().getText()));
    if (action2 instanceof ToggleUseSoftWrapsToolbarAction) {
      return new MergedWrapTextAction(((ToggleUseSoftWrapsToolbarAction)action1), (ToggleUseSoftWrapsToolbarAction)action2);
    }
    else if (action2 instanceof ScrollToTheEndToolbarAction) {
      return new MergedToggleAction(((ToggleAction)action1), (ToggleAction)action2);
    }
    else if (action2 instanceof ConsoleViewImpl.ClearAllAction) {
      return new MergedAction(action1, action2);
    }
    else {
      return action1;
    }
  });
}
 
Example #5
Source File: XValueHint.java    From consulo with Apache License 2.0 6 votes vote down vote up
public XValueHint(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Point point, @Nonnull ValueHintType type,
                  @Nonnull ExpressionInfo expressionInfo, @Nonnull XDebuggerEvaluator evaluator,
                  @Nonnull XDebugSession session) {
  super(project, editor, point, type, expressionInfo.getTextRange());

  myEvaluator = evaluator;
  myDebugSession = session;
  myExpression = XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument());
  myValueName = XDebuggerEvaluateActionHandler.getDisplayText(expressionInfo, editor.getDocument());
  myExpressionInfo = expressionInfo;

  VirtualFile file;
  ConsoleView consoleView = ConsoleViewImpl.CONSOLE_VIEW_IN_EDITOR_VIEW.get(editor);
  if (consoleView instanceof LanguageConsoleView) {
    LanguageConsoleView console = ((LanguageConsoleView)consoleView);
    file = console.getHistoryViewer() == editor ? console.getVirtualFile() : null;
  }
  else {
    file = FileDocumentManager.getInstance().getFile(editor.getDocument());
  }

  myExpressionPosition = file != null ? XDebuggerUtil.getInstance().createPositionByOffset(file, expressionInfo.getTextRange().getStartOffset()) : null;
}
 
Example #6
Source File: RunnerUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static final ConsoleView showHelperProcessRunContent(String header, OSProcessHandler runHandler, Project project, Executor defaultExecutor) {
        ProcessTerminatedListener.attach(runHandler);

        ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
        DefaultActionGroup toolbarActions = new DefaultActionGroup();

        JPanel panel = new JPanel((LayoutManager) new BorderLayout());
        panel.add((Component) consoleView.getComponent(), "Center");
        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("unknown", (ActionGroup) toolbarActions, false);
        toolbar.setTargetComponent(consoleView.getComponent());
        panel.add((Component) toolbar.getComponent(), "West");

        RunContentDescriptor runDescriptor = new RunContentDescriptor((ExecutionConsole) consoleView,
                (ProcessHandler) runHandler, (JComponent) panel, header, AllIcons.RunConfigurations.Application);
        AnAction[]
                consoleActions = consoleView.createConsoleActions();
        toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length));
        toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", (ProcessHandler) runHandler));
        toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project));

        consoleView.attachToProcess((ProcessHandler) runHandler);
//        ExecutionManager.getInstance(environment.getProject()).getContentManager().showRunContent(environment.getExecutor(), runDescriptor);
        showConsole(project, defaultExecutor, runDescriptor);
        return (ConsoleView) consoleView;
    }
 
Example #7
Source File: TestsConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TestsConsoleViewImpl(final Project project,
                            final GlobalSearchScope searchScope,
                            final boolean viewer,
                            boolean usePredefinedMessageFilter) {
  super(project, searchScope, viewer,
        new ConsoleState.NotStartedStated() {
          @Override
          public ConsoleState attachTo(ConsoleViewImpl console, ProcessHandler processHandler) {
            return new ConsoleViewRunningState(console, processHandler, this, false, !viewer);
          }
        },
        usePredefinedMessageFilter);
}
 
Example #8
Source File: LogConsoleBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private synchronized void doFilter() {
  if (myDisposed) {
    return;
  }
  final ConsoleView console = getConsoleNotNull();
  console.clear();
  myModel.processingStarted();

  final String[] lines = myOriginalDocument.toString().split("\n");
  int offset = 0;
  boolean caretPositioned = false;

  for (String line : lines) {
    final int printed = printMessageToConsole(line);
    if (printed > 0) {
      if (!caretPositioned) {
        if (Comparing.strEqual(myLineUnderSelection, line)) {
          caretPositioned = true;
          offset += myLineOffset != -1 ? myLineOffset : 0;
        }
        else {
          offset += printed;
        }
      }
    }
  }

  // we need this, because, document can change before actual scrolling, so offset may be already not at the end
  if (caretPositioned) {
    console.scrollTo(offset);
  }
  else {
    ((ConsoleViewImpl)console).requestScrollingToEnd();
  }
}
 
Example #9
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
  RunContentDescriptor descriptor = myDescriptor.get();
  ConsoleViewImpl console = ObjectUtils.tryCast(descriptor != null ? descriptor.getExecutionConsole() : null, ConsoleViewImpl.class);
  if (console == null) {
    //TODO ignore ?
    throw new IOException("The console is not available.");
  }
  console.print(new String(cbuf, off, len), myOutputType);
}
 
Example #10
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void executeQuery(@Nonnull Project project, @Nonnull VirtualFile file, @Nonnull Editor editor, @Nonnull IdeScriptEngine engine) {
  String command = getCommandText(project, editor);
  if (StringUtil.isEmptyOrSpaces(command)) return;
  String profile = getProfileText(file);
  RunContentDescriptor descriptor = getConsoleView(project, file);
  ConsoleViewImpl consoleView = (ConsoleViewImpl)descriptor.getExecutionConsole();

  prepareEngine(project, engine, descriptor);
  try {
    long ts = System.currentTimeMillis();
    //myHistoryController.getModel().addToHistory(command);
    consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
    consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
    String script = profile == null ? command : profile + "\n" + command;
    Object o = engine.eval(script);
    String prefix = "[" + (StringUtil.formatDuration(System.currentTimeMillis() - ts)) + "]";
    consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
  }
  catch (Throwable e) {
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable ex = ExceptionUtil.getRootCause(e);
    consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
  }
  selectContent(descriptor);
}
 
Example #11
Source File: XDebuggerTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getConsoleText(final @Nonnull ConsoleViewImpl consoleView) {
  WriteAction.run(() -> {
    consoleView.flushDeferredText();
  });

  return consoleView.getEditor().getDocument().getText();
}
 
Example #12
Source File: EmbeddedLinuxJVMConsoleView.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the Console View
 * @return
 */
@NotNull
public ConsoleViewImpl getConsoleView(boolean isNew) {
    if (isNew) {
        consoleView = new ConsoleViewImpl(project, false);
    }
    return consoleView;
}
 
Example #13
Source File: BlazeConsoleView.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Changes the action text to reference 'problems', not 'stack traces'. */
private static OccurenceNavigator fromConsoleView(ConsoleViewImpl console) {
  return new OccurenceNavigator() {
    @Override
    public boolean hasNextOccurence() {
      return console.hasNextOccurence();
    }

    @Override
    public boolean hasPreviousOccurence() {
      return console.hasPreviousOccurence();
    }

    @Nullable
    @Override
    public OccurenceInfo goNextOccurence() {
      return console.goNextOccurence();
    }

    @Nullable
    @Override
    public OccurenceInfo goPreviousOccurence() {
      return console.goPreviousOccurence();
    }

    @Override
    public String getNextOccurenceActionName() {
      return "Next Problem";
    }

    @Override
    public String getPreviousOccurenceActionName() {
      return "Previous Problem";
    }
  };
}
 
Example #14
Source File: BlazeConsoleView.java    From intellij with Apache License 2.0 5 votes vote down vote up
public BlazeConsoleView(Project project) {
  this.project = project;
  consoleView =
      new ConsoleViewImpl(
          this.project,
          GlobalSearchScope.allScope(project),
          /* viewer= */ false,
          /* usePredefinedFilters= */ false);

  consoleView.addMessageFilter(customFilters);
  addWrappedPredefinedFilters();
  // add target filter last, so it doesn't override other links containing a target string
  consoleView.addMessageFilter(new BlazeTargetFilter(false));
  Disposer.register(this, consoleView);
}
 
Example #15
Source File: LogView.java    From logviewer with Apache License 2.0 5 votes vote down vote up
void addLogLine(@NotNull String line) {
    super.addMessage(line);
    if (getOriginalDocument().length() > defaultCycleBufferSize) {
        if (getConsole() != null) {
            ((ConsoleViewImpl) getConsole()).flushDeferredText();
        }
        getOriginalDocument().delete(0, defaultCycleBufferSize / 4);
        refresh("Clearing old logs");
    }
}
 
Example #16
Source File: PromptConsoleView.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
PromptConsoleView(@NotNull Project project, boolean viewer, final boolean attachToStdOut) {
    super(project, GlobalSearchScope.allScope(project), viewer, new ConsoleState.NotStartedStated() {
        @NotNull
        @Override
        public ConsoleState attachTo(@NotNull ConsoleViewImpl console, ProcessHandler processHandler) {
            return new ConsoleViewRunningState(console, processHandler, this, attachToStdOut, true);
        }
    }, true);
    m_promptConsole = new PromptConsole(project, this);
    Disposer.register(this, m_promptConsole);
}
 
Example #17
Source File: BuckDebugPanelImpl.java    From buck with Apache License 2.0 4 votes vote down vote up
public BuckDebugPanelImpl(Project project) {
  outputConsole = new ConsoleViewImpl(project, false);
  Disposer.register(project, outputConsole);
}
 
Example #18
Source File: EmbeddedLinuxJVMConsoleView.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 4 votes vote down vote up
public EmbeddedLinuxJVMConsoleView(@NotNull Project project) {
    this.project = project;
    consoleView = new ConsoleViewImpl(project, false);
    Disposer.register(this, consoleView);
}
 
Example #19
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void selectContent(RunContentDescriptor descriptor) {
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  ConsoleViewImpl consoleView = ObjectUtils.assertNotNull((ConsoleViewImpl)descriptor.getExecutionConsole());
  ExecutionManager.getInstance(consoleView.getProject()).getContentManager().toFrontRunContent(executor, descriptor);
}
 
Example #20
Source File: TextConsoleBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected ConsoleView createConsole() {
  return new ConsoleViewImpl(myProject, myScope, myViewer, myUsePredefinedMessageFilter);
}