forked from alibaba/termd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventsExample.java
More file actions
58 lines (50 loc) · 1.4 KB
/
Copy pathEventsExample.java
File metadata and controls
58 lines (50 loc) · 1.4 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package examples.events;
import io.termd.core.function.BiConsumer;
import io.termd.core.function.Consumer;
import io.termd.core.tty.TtyConnection;
import io.termd.core.tty.TtyEvent;
import io.termd.core.util.Vector;
/**
* This example show how to handle TTY events.
*/
public class EventsExample {
public static void handle(final TtyConnection conn) {
conn.setEventHandler(new BiConsumer<TtyEvent, Integer>() {
@Override
public void accept(TtyEvent event, Integer key) {
switch (event) {
case INTR:
conn.write("You did a Ctrl-C\n");
break;
case SUSP:
conn.write("You did a Ctrl-Z\n");
break;
case EOF:
conn.write("You did a Ctrl-D: closing\n");
conn.close();
break;
}
}
});
conn.setSizeHandler(new Consumer<Vector>() {
@Override
public void accept(Vector size) {
conn.write("You resized your terminal to " + size + "\n");
}
});
conn.setTerminalTypeHandler(new Consumer<String>() {
@Override
public void accept(String term) {
conn.write("Your terminal is " + term + "\n");
}
});
conn.setStdinHandler(new Consumer<int[]>() {
@Override
public void accept(int[] keys) {
for (int key : keys) {
conn.write("You typed " + key + "\n");
}
}
});
}
}