/** * Creates and displays command-line console for user. * * @param module module to display console for. * @param consoleName Console name (would be used in prompt, history etc) * @param commandsAndDefaultExecutor list of commands available for this console. You may pass * null here, but in this case no validation nor suggestion will be available. Default * executor (may be null) to be used when user executes unknwon command Whole pair be null, * but no executor would be registered, so you will need to use {@link * LanguageConsoleBuilder#registerExecuteAction(LanguageConsoleView, Consumer, String, String, * Condition)} by yourself passing this method result as arg to enable execution, history etc. * @return newly created console. You do not need to do anything with this value to display * console: it will be displayed automatically */ @NotNull public static LanguageConsoleView createConsole( @NotNull final Module module, @NotNull final String consoleName, @Nullable final Pair<List<Command>, CommandExecutor> commandsAndDefaultExecutor) { final Project project = module.getProject(); final CommandConsole console = CommandConsole.createConsole(module, consoleName, commandsAndDefaultExecutor); // Show console on "toolwindow" WindowWithActions.showConsoleWithProcess( console, console.getEditor().getComponent(), consoleName, project, null); ArgumentHintLayer.attach(console); // Display [arguments] return console; }
/** * @param module module console runs on * @param title console title * @param commandsAndDefaultExecutor List of commands (to be injected into {@link * CommandLineFile}) if any and executor to be used when user executes unknown command. Both * may be null. Execution is passed to command if command exist, passed to default executor * otherwise. With out of commands default executor will always be used. With out of executor, * no execution would be possible at all. * @return console */ @NotNull static CommandConsole createConsole( @NotNull final Module module, @NotNull final String title, @Nullable final Pair<List<Command>, CommandExecutor> commandsAndDefaultExecutor) { final CommandConsole console = new CommandConsole(module, title, commandsAndDefaultExecutor); console.setEditable(true); LanguageConsoleBuilder.registerExecuteAction(console, console, title, title, console); console.switchToCommandMode(); console .getComponent(); // For some reason console does not have component until this method is // called which leads to some errros. console.getConsoleEditor().getSettings().setAdditionalLinesCount(2); // to prevent PY-15583 Disposer.register(module.getProject(), console); // To dispose console when project disposes console.addMessageFilter(new UrlFilter()); return console; }