AtomicInteger ai = new AtomicInteger(0); server.shellHandler(shell -> { shell.setPrompt(s -> { try { return "C: " + ai.incrementAndGet();
/** * Set a new prompt in this session. * @param prompt the new prompt will be calculated when it's needed. */ public void setPrompt(Function<io.vertx.rxjava.ext.shell.session.Session, String> prompt) { delegate.setPrompt(new java.util.function.Function<io.vertx.ext.shell.session.Session,java.lang.String>() { public java.lang.String apply(io.vertx.ext.shell.session.Session arg) { String ret = prompt.apply(io.vertx.rxjava.ext.shell.session.Session.newInstance(arg)); return ret; } }); }
/** * Set a new prompt in this session. * @param prompt the new prompt will be calculated when it's needed. */ public void setPrompt(Function<io.vertx.rxjava.ext.shell.session.Session, String> prompt) { delegate.setPrompt(new java.util.function.Function<io.vertx.ext.shell.session.Session,java.lang.String>() { public java.lang.String apply(io.vertx.ext.shell.session.Session arg) { String ret = prompt.apply(io.vertx.rxjava.ext.shell.session.Session.newInstance(arg)); return ret; } }); }
@Test public void testPrompt(TestContext context) { commands = new TestCommands(vertx); ShellServer server = ShellServer.create(vertx, new ShellServerOptions() .setWelcomeMessage("") .setSessionTimeout(100) .setReaperInterval(100)); server.shellHandler(shell -> shell.setPrompt(s -> "FOOPROMPT")); TestTermServer termServer = new TestTermServer(vertx); server.registerTermServer(termServer); server. registerCommandResolver(CommandResolver.baseCommands(vertx)). registerCommandResolver(commands). listen(context.asyncAssertSuccess()); TestTtyConnection conn = termServer.openConnection(); Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { context.assertEquals(null, conn.checkWritten("FOOPROMPTfoo\n")); process.stdinHandler(cp -> { context.fail(); }); process.endHandler(v -> { async.complete(); } ); process.end(); })); conn.read("foo\r"); async.awaitSuccess(5000); }