/** * Write a string to the client. * * @param s the string to write */ default TtyConnection write(String s) { int[] codePoints = Helper.toCodePoints(s); stdoutHandler().accept(codePoints); return this; }
/** * Write a string to the client. * * @param s the string to write */ default TtyConnection write(String s) { int[] codePoints = Helper.toCodePoints(s); stdoutHandler().accept(codePoints); return this; }
private void onStdOut(TtyConnection conn, int[] buffer) { conn.execute(() -> { conn.stdoutHandler().accept(buffer); }); if (processStdoutListener != null) { processStdoutListener.accept(buffer); } } }
private void onStdOut(TtyConnection conn, int[] buffer) { conn.execute(() -> { conn.stdoutHandler().accept(buffer); }); if (processStdoutListener != null) { processStdoutListener.accept(buffer); } } }
public void echo(int... codePoints) { Consumer<int[]> out = conn.stdoutHandler(); for (int codePoint : codePoints) { if (codePoint < 32) { if (codePoint == '\t') { out.accept(new int[]{'\t'}); } else if (codePoint == '\b') { out.accept(new int[]{'\b', ' ', '\b'}); } else if (codePoint == '\r' || codePoint == '\n') { out.accept(new int[]{'\n'}); } else { out.accept(new int[]{'^', codePoint + 64}); } } else { if (codePoint == 127) { out.accept(new int[]{'\b', ' ', '\b'}); } else { out.accept(new int[]{codePoint}); } } } } }
/** * 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(); }
@Override public void accept(TtyConnection conn) { requestCount.incrementAndGet(); conn.stdoutHandler().accept(new int[]{'%', ' '}); } });
public TtyBridge readline() { 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)) { log.trace("Server is adding function to readline: {}", function); readline.addFunction(function); } conn.setTerminalTypeHandler(term -> { // Not used yet but we should propagage this to the process builder // System.out.println("CLIENT $TERM=" + term); }); conn.stdoutHandler().accept(Helper.toCodePoints("Welcome sir\n")); read(conn, readline); return this; }
public TtyBridge readline() { 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)) { log.trace("Server is adding function to readline: {}", function); readline.addFunction(function); } conn.setTerminalTypeHandler(term -> { // Not used yet but we should propagage this to the process builder // System.out.println("CLIENT $TERM=" + term); }); conn.stdoutHandler().accept(Helper.toCodePoints("Welcome sir\n")); read(conn, readline); return this; }
@Test public void testWrite() throws Exception { final AtomicInteger requestCount = new AtomicInteger(); server(conn -> { requestCount.incrementAndGet(); conn.stdoutHandler().accept(new int[]{'%', ' '}); }); assertConnect(); assertEquals("% ", assertReadString(2)); assertEquals(1, requestCount.get()); }
@Test public void testWrite() throws Exception { final AtomicInteger requestCount = new AtomicInteger(); server(conn -> { requestCount.incrementAndGet(); conn.stdoutHandler().accept(new int[]{'%', ' '}); }); assertConnect(); assertEquals("% ", assertReadString(2)); assertEquals(1, requestCount.get()); }
Consumer<int[]> out = conn.stdoutHandler(); out.accept(new int[]{'\r'}); while (curHeight != endHeight) {
Consumer<int[]> out = conn.stdoutHandler(); out.accept(new int[]{'\r'}); while (curHeight != endHeight) {
/** * Redraw the current line. */ public void redraw() { LineBuffer toto = new LineBuffer(); toto.insert(Helper.toCodePoints(currentPrompt)); toto.insert(buffer.toArray()); toto.setCursor(currentPrompt.length() + buffer.getCursor()); LineBuffer abc = new LineBuffer(); abc.update(toto, conn.stdoutHandler(), size.x()); }
/** * Redraw the current line. */ public void redraw() { LineBuffer toto = new LineBuffer(); toto.insert(Helper.toCodePoints(currentPrompt)); toto.insert(buffer.toArray()); toto.setCursor(currentPrompt.length() + buffer.getCursor()); LineBuffer abc = new LineBuffer(); abc.update(toto, conn.stdoutHandler(), size.x()); }
@Test public void testRead() throws Exception { final ArrayBlockingQueue<int[]> queue = new ArrayBlockingQueue<>(1); server(conn -> conn.setStdinHandler(data -> { queue.add(data); conn.stdoutHandler().accept(new int[]{'h', 'e', 'l', 'l', 'o'}); })); assertConnect(); assertWriteln(""); int[] data = queue.poll(10, TimeUnit.SECONDS); assertTrue(Arrays.equals(new int[]{'\r'}, data)); assertEquals("hello", assertReadString(5)); }
@Test public void testRead() throws Exception { final ArrayBlockingQueue<int[]> queue = new ArrayBlockingQueue<>(1); server(conn -> conn.setStdinHandler(data -> { queue.add(data); conn.stdoutHandler().accept(new int[]{'h', 'e', 'l', 'l', 'o'}); })); assertConnect(); assertWriteln(""); int[] data = queue.poll(10, TimeUnit.SECONDS); assertTrue(Arrays.equals(new int[]{'\r'}, data)); assertEquals("hello", assertReadString(5)); }
private void refresh(LineBuffer update, int width) { LineBuffer copy3 = new LineBuffer(); IntStream.Builder consumer = IntStream.builder(); copy3.insert(Helper.toCodePoints(currentPrompt)); copy3.insert(buffer().toArray()); copy3.setCursor(currentPrompt.length() + buffer().getCursor()); LineBuffer copy2 = new LineBuffer(); copy2.insert(Helper.toCodePoints(currentPrompt)); copy2.insert(update.toArray()); copy2.setCursor(currentPrompt.length() + update.getCursor()); copy3.update(copy2, data -> { for (int cp : data) { consumer.accept(cp); } }, width); conn.stdoutHandler().accept(consumer.build().toArray()); buffer.clear(); buffer.insert(update.toArray()); buffer.setCursor(update.getCursor()); }
private void refresh(LineBuffer update, int width) { LineBuffer copy3 = new LineBuffer(); IntStream.Builder consumer = IntStream.builder(); copy3.insert(Helper.toCodePoints(currentPrompt)); copy3.insert(buffer().toArray()); copy3.setCursor(currentPrompt.length() + buffer().getCursor()); LineBuffer copy2 = new LineBuffer(); copy2.insert(Helper.toCodePoints(currentPrompt)); copy2.insert(update.toArray()); copy2.setCursor(currentPrompt.length() + update.getCursor()); copy3.update(copy2, data -> { for (int cp : data) { consumer.accept(cp); } }, width); conn.stdoutHandler().accept(consumer.build().toArray()); buffer.clear(); buffer.insert(update.toArray()); buffer.setCursor(update.getCursor()); }