Search in sources :

Example 1 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class HelloWorldCommand method start.

@Override
public void start() throws Exception {
    Command helloWorld = CommandBuilder.command("hello-world").processHandler(process -> {
        process.write("hello world\n");
        process.end();
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(helloWorld);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 2 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class RunShell method start.

@Override
public void start() throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    service.start();
}
Also used : ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 3 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class StarwarsCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("starwars").processHandler(process -> {
        // Connect the client
        NetClient client = process.vertx().createNetClient();
        client.connect(23, "towel.blinkenlights.nl", ar -> {
            if (ar.succeeded()) {
                NetSocket socket = ar.result();
                // Ctrl-C closes the socket
                process.interruptHandler(v -> {
                    socket.close();
                });
                // 
                socket.handler(buff -> {
                    // Push the data to the Shell
                    process.write(buff.toString("UTF-8"));
                }).exceptionHandler(err -> {
                    err.printStackTrace();
                    socket.close();
                });
                // When socket closes, end the command
                socket.closeHandler(v -> {
                    process.end();
                });
            } else {
                process.write("Could not connect to remote Starwars server\n").end();
            }
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) NetClient(io.vertx.core.net.NetClient) Runner(io.vertx.example.util.Runner) NetSocket(io.vertx.core.net.NetSocket) NetSocket(io.vertx.core.net.NetSocket) ShellService(io.vertx.ext.shell.ShellService) NetClient(io.vertx.core.net.NetClient) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 4 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class TopCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("top").processHandler(process -> {
        long id = process.vertx().setPeriodic(500, id_ -> {
            StringBuilder buf = new StringBuilder();
            Formatter formatter = new Formatter(buf);
            List<Thread> threads = new ArrayList<>(Thread.getAllStackTraces().keySet());
            for (int i = 1; i <= process.height(); i++) {
                // Change cursor position and erase line with ANSI escape code magic
                buf.append("\033[").append(i).append(";1H\033[K");
                // 
                String format = "  %1$-5s %2$-20s %3$-50s %4$s";
                if (i == 1) {
                    formatter.format(format, "ID", "STATE", "NAME", "GROUP");
                } else {
                    int index = i - 2;
                    if (index < threads.size()) {
                        Thread thread = threads.get(index);
                        formatter.format(format, thread.getId(), thread.getState().name(), thread.getName(), thread.getThreadGroup().getName());
                    }
                }
            }
            process.write(buf.toString());
        });
        // Terminate when user hits Ctrl-C
        process.interruptHandler(v -> {
            vertx.cancelTimer(id);
            process.end();
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) List(java.util.List) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) Formatter(java.util.Formatter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class EchoKeyboardCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("echokeyboard").processHandler(process -> {
        // Echo
        process.stdinHandler(keys -> {
            process.write(keys.replace('\r', '\n'));
        });
        // Terminate when user hits Ctrl-C
        process.interruptHandler(v -> {
            process.end();
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) List(java.util.List) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Aggregations

TelnetTermOptions (io.vertx.ext.shell.term.TelnetTermOptions)7 ShellService (io.vertx.ext.shell.ShellService)6 ShellServiceOptions (io.vertx.ext.shell.ShellServiceOptions)6 AbstractVerticle (io.vertx.core.AbstractVerticle)5 Runner (io.vertx.example.util.Runner)5 Command (io.vertx.ext.shell.command.Command)5 CommandBuilder (io.vertx.ext.shell.command.CommandBuilder)5 CommandRegistry (io.vertx.ext.shell.command.CommandRegistry)5 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2 List (java.util.List)2 Argument (io.vertx.core.cli.Argument)1 CLI (io.vertx.core.cli.CLI)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 NetClient (io.vertx.core.net.NetClient)1 NetSocket (io.vertx.core.net.NetSocket)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1