1 | !include #1003380 // Chat |
2 | |
3 | sclass BotChat {
|
4 | Chat chat; |
5 | O dialogBot, backend; |
6 | JTextArea thoughtsArea; |
7 | |
8 | *(O dialogBot) { this(dialogBot, null); }
|
9 | |
10 | *(O _dialogBot, O backend) {
|
11 | if (backend is a S) backend = run((S) backend); |
12 | this.backend = backend; |
13 | dialogBot = _dialogBot; |
14 | //callOpt(dialogBot, "noRewind"); |
15 | |
16 | swingAndWait(r {
|
17 | thoughtsArea = new JTextArea; |
18 | |
19 | chat = new Chat; |
20 | chat.logFile = getProgramFile("log.txt");
|
21 | |
22 | chat.onEnter_post = r {
|
23 | call(dialogBot, "take", E.q(chat.input())); |
24 | postIt(slurp(dialogBot, "getSingleOutput")); |
25 | }; |
26 | |
27 | updateThoughts(); |
28 | |
29 | JFrame frame = showFrame(makeTitle(), |
30 | hgrid(chat, withTitle("Thoughts", thoughtsArea)));
|
31 | setFrameWidth(frame, 800); |
32 | chat.requestFocus(); |
33 | }); |
34 | } |
35 | |
36 | S makeTitle() {
|
37 | ret programTitle(); |
38 | } |
39 | |
40 | void postIt(final L<E> l) {
|
41 | for (int i = 0; i < l(l); i++) {
|
42 | E e = l.get(i); |
43 | if (e.a()) |
44 | chatAppend("Bot: " + e.a + "\n");
|
45 | else if (e.state()) {
|
46 | chatAppend("[" + e.state + "]\n");
|
47 | final int _i = i+1; |
48 | Runnable l8r = r { awt { postIt(subList(l, _i)); } };
|
49 | if ((bool) call(backend, "action", e.state, l8r)) |
50 | break; |
51 | } |
52 | } |
53 | updateThoughts(); |
54 | } |
55 | |
56 | void chatAppend(S s) {
|
57 | if (s.startsWith("[") && matchStart("bot pauses", s)) ret;
|
58 | chat.append(s); |
59 | } |
60 | |
61 | void updateThoughts() {
|
62 | S s; |
63 | try {
|
64 | s = (S) callOpt(dialogBot, "thoughts"); |
65 | } catch e {
|
66 | s = getStackTrace(e); |
67 | } |
68 | if (empty(s)) s = "No thoughts in " + getClassName(dialogBot); |
69 | //print("Thoughts: " + s);
|
70 | thoughtsArea.setText(s); |
71 | } |
72 | } |
Began life as a copy of #1003406
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1003416 |
| Snippet name: | class BotChat (old) |
| Eternal ID of this version: | #1003416/1 |
| Text MD5: | cd9703d7b4e38d7c70b115256b18578e |
| Author: | stefan |
| Category: | javax / talking robots |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-07-19 16:48:34 |
| Source code size: | 1769 bytes / 72 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 957 / 955 |
| Referenced in: | [show references] |