@Override public Tty write(String data) { conn.write(data); return this; }
@Override public Term write(String data) { conn.write(data); return this; }
@Override public void accept(TtyConnection conn) { // 20AC does not exists in ISO_8859_1 and is replaced by `?` conn.write("\u20AC"); } });
@Override public void execute(TtyConnection conn, List<String> args) throws Exception { StringBuilder msg = new StringBuilder("Demo term, try commands: "); Command[] commands = Command.values(); for (int i = 0;i < commands.length;i++) { if (i > 0) { msg.append(","); } msg.append(" ").append(commands[i].name()); } msg.append("...\n"); conn.write(msg.toString()); } },
@Override public void execute(TtyConnection conn, List<String> args) throws Exception { StringBuilder msg = new StringBuilder("Demo term, try commands: "); Command[] commands = Command.values(); for (int i = 0;i < commands.length;i++) { if (i > 0) { msg.append(","); } msg.append(" ").append(commands[i].name()); } msg.append("...\n"); conn.write(msg.toString()); } },
@Override public void execute(TtyConnection conn, List<String> args) throws Exception { conn.write("Current window size " + conn.size() + ", try resize it\n"); // Refresh the screen with the new size conn.setSizeHandler(size -> { conn.write("Window resized " + size + "\n"); }); try { // Wait until interrupted new CountDownLatch(1).await(); } finally { conn.setSizeHandler(null); } } },
@Override public void execute(TtyConnection conn, List<String> args) throws Exception { conn.write("Current window size " + conn.size() + ", try resize it\n"); // Refresh the screen with the new size conn.setSizeHandler(size -> { conn.write("Window resized " + size + "\n"); }); try { // Wait until interrupted new CountDownLatch(1).await(); } finally { conn.setSizeHandler(null); } } },
@Override public void execute(TtyConnection conn, List<String> args) throws Exception { // Subscribe to key events and print them conn.setStdinHandler(keys -> { for (int key : keys) { conn.write(key + " pressed\n"); } }); try { // Wait until interrupted new CountDownLatch(1).await(); } finally { conn.setStdinHandler(null); } } },
/** * Read a line until a request can be processed. * * @param requestHandler the requestHandler */ public void readline(TtyConnection conn, String prompt, Consumer<String> requestHandler, Consumer<Completion> completionHandler) { synchronized (this) { if (interaction != null) { throw new IllegalStateException("Already reading a line"); } interaction = new Interaction(conn, prompt, requestHandler, completionHandler); } interaction.install(); conn.write(prompt); schedulePendingEvent(); }
/** * Read a line until a request can be processed. * * @param requestHandler the requestHandler */ public void readline(TtyConnection conn, String prompt, Consumer<String> requestHandler, Consumer<Completion> completionHandler) { synchronized (this) { if (interaction != null) { throw new IllegalStateException("Already reading a line"); } interaction = new Interaction(conn, prompt, requestHandler, completionHandler); } interaction.install(); conn.write(prompt); schedulePendingEvent(); }
/** * Write a block of text below the current edition line, a {@code CRLF} sequence is inserted before the * block of text.<p/> * * @param text the text to insert inline */ public void suggest(int[] text) { if (!done.compareAndSet(false, true)) { throw new IllegalStateException(); } interaction.conn.write("\n"); interaction.conn.stdoutHandler().accept(text); interaction.redraw(); interaction.resume(); }
/** * Write a block of text below the current edition line, a {@code CRLF} sequence is inserted before the * block of text.<p/> * * @param text the text to insert inline */ public void suggest(int[] text) { if (!done.compareAndSet(false, true)) { throw new IllegalStateException(); } interaction.conn.write("\n"); interaction.conn.stdoutHandler().accept(text); interaction.redraw(); interaction.resume(); }
public void accept(final TtyConnection conn) { InputStream inputrc = Keymap.class.getResourceAsStream("inputrc"); Keymap keymap = new Keymap(inputrc); Readline readline = new Readline(keymap); for (io.termd.core.readline.Function function : Helper.loadServices(Thread.currentThread().getContextClassLoader(), io.termd.core.readline.Function.class)) { readline.addFunction(function); } conn.write("Welcome to Term.d shell example\n\n"); read(conn, readline); }
public void accept(final TtyConnection conn) { InputStream inputrc = Keymap.class.getResourceAsStream("inputrc"); Keymap keymap = new Keymap(inputrc); Readline readline = new Readline(keymap); for (io.termd.core.readline.Function function : Helper.loadServices(Thread.currentThread().getContextClassLoader(), io.termd.core.readline.Function.class)) { readline.addFunction(function); } conn.write("Welcome to Term.d shell example\n\n"); read(conn, readline); }
@Test public void testDifferentCharset() throws Exception { charset = StandardCharsets.ISO_8859_1; server(conn -> { // 20AC does not exists in ISO_8859_1 and is replaced by `?` conn.write("\u20AC"); }); assertConnect(); String s = assertReadString(1); assertEquals("?", s); } }
@Test public void testDifferentCharset() throws Exception { charset = StandardCharsets.ISO_8859_1; server(conn -> { // 20AC does not exists in ISO_8859_1 and is replaced by `?` conn.write("\u20AC"); }); assertConnect(); String s = assertReadString(1); assertEquals("?", s); } }