forked from alibaba/termd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadlineExample.java
More file actions
35 lines (30 loc) · 904 Bytes
/
Copy pathReadlineExample.java
File metadata and controls
35 lines (30 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package examples.readline;
import io.termd.core.function.Consumer;
import io.termd.core.readline.Functions;
import io.termd.core.readline.Keymap;
import io.termd.core.readline.Readline;
import io.termd.core.tty.TtyConnection;
/**
* Shows how to use async Readline.
*/
public class ReadlineExample {
public static void handle(TtyConnection conn) {
readline(
new Readline(Keymap.getDefault()).addFunctions(Functions.loadDefaults()),
conn);
}
public static void readline(final Readline readline, final TtyConnection conn) {
readline.readline(conn, "% ", new Consumer<String>() {
@Override
public void accept(String line) {
if (line == null) {
conn.write("Logout").close();
} else {
conn.write("User entered " + line + "\n");
// Read line again
readline(readline, conn);
}
}
});
}
}