2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.jetbrains.commandInterface.console;
18 import com.intellij.execution.console.LanguageConsoleBuilder;
19 import com.intellij.execution.console.LanguageConsoleView;
20 import com.intellij.openapi.module.Module;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.util.Condition;
23 import com.intellij.openapi.util.Pair;
24 import com.intellij.util.Consumer;
25 import com.jetbrains.commandInterface.command.Command;
26 import com.jetbrains.commandInterface.command.CommandExecutor;
27 import com.jetbrains.toolWindowWithActions.WindowWithActions;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
31 import java.util.List;
34 * Displays command-line console for user.
36 * @author Ilya.Kazakevich
38 public final class CommandLineConsoleApi {
40 private CommandLineConsoleApi() {
44 * Creates and displays command-line console for user.
46 * @param module module to display console for.
47 * @param consoleName Console name (would be used in prompt, history etc)
48 * @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.
49 * Default executor (may be null) to be used when user executes unknwon command
50 * Whole pair be null, but no executor would be registered, so you will need to use
51 * {@link LanguageConsoleBuilder#registerExecuteAction(LanguageConsoleView, Consumer, String, String, Condition)}
52 * by yourself passing this method result as arg to enable execution, history etc.
53 * @return newly created console. You do not need to do anything with this value to display console: it will be displayed automatically
56 public static LanguageConsoleView createConsole(
57 @NotNull final Module module,
58 @NotNull final String consoleName,
59 @Nullable final Pair<List<Command>, CommandExecutor> commandsAndDefaultExecutor) {
60 return createConsole(module, consoleName, consoleName, commandsAndDefaultExecutor);
65 public static LanguageConsoleView createConsole(
66 @NotNull final Module module,
67 @NotNull final String consoleName,
68 @NotNull final String promptName,
69 @Nullable final Pair<List<Command>, CommandExecutor> commandsAndDefaultExecutor) {
70 final Project project = module.getProject();
71 final CommandConsole console = CommandConsole.createConsole(module, promptName, commandsAndDefaultExecutor);
73 // Show console on "toolwindow"
74 WindowWithActions.showConsoleWithProcess(console,
75 console.getEditor().getComponent(),
80 ArgumentHintLayer.attach(console); // Display [arguments]