Search in sources :

Example 1 with ReadlineConsole

use of org.aesh.readline.ReadlineConsole in project galleon by wildfly.

the class CliMain method startInteractive.

private static void startInteractive(PmSession pmSession, CliTerminalConnection connection, boolean paging) throws Throwable {
    pmSession.setOut(connection.getOutput());
    pmSession.setErr(connection.getOutput());
    // Side effect is to resolve plugins.
    pmSession.getUniverse().resolveBuiltinUniverse();
    Settings<? extends CommandInvocation, ? extends ConverterInvocation, ? extends CompleterInvocation, ? extends ValidatorInvocation, ? extends OptionActivator, ? extends CommandActivator> settings = buildSettings(pmSession, connection, new InteractiveInvocationProvider(pmSession, paging));
    ReadlineConsole console = new ReadlineConsole(settings);
    pmSession.setAeshContext(console.context());
    console.setPrompt(pmSession.buildPrompt());
    // connection is automatically closed when exit command or Ctrl-D
    console.start();
}
Also used : ReadlineConsole(org.aesh.readline.ReadlineConsole) InteractiveInvocationProvider(org.jboss.galleon.cli.terminal.InteractiveInvocationProvider)

Example 2 with ReadlineConsole

use of org.aesh.readline.ReadlineConsole in project quarkus by quarkusio.

the class AeshConsole method runAeshCli.

public void runAeshCli() {
    if (ConsoleCliManager.commands.isEmpty()) {
        System.out.println("No commands registered, please wait for Quarkus to start before using the console");
        return;
    }
    try {
        pauseOutput = true;
        delegateConnection = new DelegateConnection(connection);
        connection.write(ALTERNATE_SCREEN_BUFFER);
        if (firstConsoleRun) {
            connection.write("You are now in Quarkus Terminal. Your app is still running. Use `help` or tab completion to explore, `quit` or `q` to return to your application.\n");
            firstConsoleRun = false;
        }
        AeshCommandRegistryBuilder<CommandInvocation> commandBuilder = AeshCommandRegistryBuilder.builder();
        ConsoleCliManager.commands.forEach(commandBuilder::command);
        CommandRegistry registry = commandBuilder.create();
        Settings settings = SettingsBuilder.builder().enableExport(false).enableAlias(true).aliasManager(new AliasManager(Paths.get(System.getProperty("user.home")).resolve(ALIAS_FILE).toFile(), true)).connection(delegateConnection).commandRegistry(registry).build();
        aeshConsole = new ReadlineConsole(settings);
        aeshConsole.setPrompt("quarkus$ ");
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    aeshConsole.start();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "Quarkus integrated CLI thread");
        t.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CommandRegistry(org.aesh.command.registry.CommandRegistry) IOException(java.io.IOException) IOException(java.io.IOException) CommandInvocation(org.aesh.command.invocation.CommandInvocation) AliasManager(org.aesh.readline.alias.AliasManager) ReadlineConsole(org.aesh.readline.ReadlineConsole) Settings(org.aesh.command.settings.Settings)

Example 3 with ReadlineConsole

use of org.aesh.readline.ReadlineConsole in project infinispan by infinispan.

the class CLI method interactive.

private CommandResult interactive(Shell shell) {
    // We now start an interactive CLI
    CommandRegistry commandRegistry = initializeCommands();
    context.setRegistry(commandRegistry);
    CliAliasManager aliasManager;
    try {
        aliasManager = new CliAliasManager(context.getConfigPath().resolve("aliases").toFile(), true, commandRegistry);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    SettingsBuilder settings = SettingsBuilder.builder();
    settings.enableAlias(true).aliasManager(aliasManager).historyFile(context.getConfigPath().resolve("history").toFile()).outputStream(System.out).outputStreamError(System.err).inputStream(System.in).commandActivatorProvider(new ContextAwareCommandActivatorProvider(context)).commandInvocationProvider(new ContextAwareCommandInvocationProvider(context)).commandNotFoundHandler(new CliCommandNotFoundHandler()).completerInvocationProvider(new ContextAwareCompleterInvocationProvider(context)).commandRegistry(commandRegistry).aeshContext(context).quitHandler(new ContextAwareQuitHandler(context));
    if (shell instanceof AeshDelegatingShell) {
        settings.connection(((AeshDelegatingShell) shell).getConnection());
    }
    ReadlineConsole console = new ReadlineConsole(settings.build());
    context.setConsole(console);
    try {
        console.start();
        return CommandResult.SUCCESS;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SettingsBuilder(org.aesh.command.settings.SettingsBuilder) CommandRegistry(org.aesh.command.registry.CommandRegistry) CliAliasManager(org.infinispan.cli.impl.CliAliasManager) AeshDelegatingShell(org.infinispan.cli.impl.AeshDelegatingShell) ReadlineConsole(org.aesh.readline.ReadlineConsole) ContextAwareQuitHandler(org.infinispan.cli.impl.ContextAwareQuitHandler) IOException(java.io.IOException) CliCommandNotFoundHandler(org.infinispan.cli.impl.CliCommandNotFoundHandler) ContextAwareCompleterInvocationProvider(org.infinispan.cli.completers.ContextAwareCompleterInvocationProvider) ContextAwareCommandActivatorProvider(org.infinispan.cli.activators.ContextAwareCommandActivatorProvider) ContextAwareCommandInvocationProvider(org.infinispan.cli.impl.ContextAwareCommandInvocationProvider)

Aggregations

ReadlineConsole (org.aesh.readline.ReadlineConsole)3 IOException (java.io.IOException)2 CommandRegistry (org.aesh.command.registry.CommandRegistry)2 CommandInvocation (org.aesh.command.invocation.CommandInvocation)1 Settings (org.aesh.command.settings.Settings)1 SettingsBuilder (org.aesh.command.settings.SettingsBuilder)1 AliasManager (org.aesh.readline.alias.AliasManager)1 ContextAwareCommandActivatorProvider (org.infinispan.cli.activators.ContextAwareCommandActivatorProvider)1 ContextAwareCompleterInvocationProvider (org.infinispan.cli.completers.ContextAwareCompleterInvocationProvider)1 AeshDelegatingShell (org.infinispan.cli.impl.AeshDelegatingShell)1 CliAliasManager (org.infinispan.cli.impl.CliAliasManager)1 CliCommandNotFoundHandler (org.infinispan.cli.impl.CliCommandNotFoundHandler)1 ContextAwareCommandInvocationProvider (org.infinispan.cli.impl.ContextAwareCommandInvocationProvider)1 ContextAwareQuitHandler (org.infinispan.cli.impl.ContextAwareQuitHandler)1 InteractiveInvocationProvider (org.jboss.galleon.cli.terminal.InteractiveInvocationProvider)1