OLD | NEW |
1 # Moterm example application | 1 # Moterm example application |
2 | 2 |
3 `moterm_example_app` is an example application that embeds | 3 `moterm_example_app` is an example application that embeds |
4 [Moterm](../../apps/moterm), uses it to provide a prompt, and allows it to be | 4 [Moterm](../../apps/moterm), uses it to provide a prompt, and allows it to be |
5 connected to other applications (which should implement the | 5 connected to other applications (which should provide the |
6 `mojo.terminal.TerminalClient` interface). | 6 `mojo.terminal.TerminalClient` service). |
7 | 7 |
8 ## Running | 8 ## Running |
9 | 9 |
10 On Linux, run it in the usual way, e.g.: | 10 On Linux, run it in the usual way, e.g.: |
11 | 11 |
12 $ mojo/devtools/common/mojo_run --enable-multiprocess "mojo:window_manager m
ojo:moterm_example_app" | 12 $ mojo/devtools/common/mojo_run --enable-multiprocess "mojo:window_manager m
ojo:moterm_example_app" |
13 | 13 |
14 You'll probably need to click on the window to give it keyboard focus. You may | 14 You'll probably need to click on the window to give it keyboard focus. You may |
15 also want to resize the window (especially horizontally) to make it bigger. | 15 also want to resize the window (especially horizontally) to make it bigger. |
16 | 16 |
17 At the `:)` prompt, you may enter the URL for any application implementing the | 17 At the `:)` prompt, you may enter the URL for any application providing the |
18 `mojo.terminal.TerminalClient` interface. E.g.: | 18 `mojo.terminal.TerminalClient` service. |
| 19 |
| 20 ### Example 1: Dart netcat |
| 21 |
| 22 An example of a terminal client application written in Dart is `dart_netcat`: |
19 | 23 |
20 :) mojo:dart_netcat | 24 :) mojo:dart_netcat |
21 | 25 |
22 At this point, the terminal's input/output is transferred to the specified | 26 At this point, the terminal's input/output is transferred to the specified |
23 application. In this case, it just outputs a help message and closes the | 27 application. In this case, it just outputs a help message and closes the |
24 terminal, returning you to the `:)` prompt. You may also try: | 28 terminal, returning you to the `:)` prompt. You may also try: |
25 | 29 |
26 :) mojo:dart_netcat?localhost&port=80 | 30 :) mojo:dart_netcat?localhost&port=80 |
27 | 31 |
28 In this case, `mojo:dart_netcat` will make a TCP connection to the specified | 32 In this case, `mojo:dart_netcat` will make a TCP connection to the specified |
29 host/port. Assuming you have a web server running on your machine, you may try | 33 host/port. Assuming you have a web server running on your machine, you may try |
30 entering: | 34 entering: |
31 | 35 |
32 GET / | 36 GET / |
33 | 37 |
34 (It's probably a bug in `mojo:dart_netcat` that it doesn't close the terminal | 38 (It's probably a bug in `mojo:dart_netcat` that it doesn't close the terminal |
35 "file". You can press Control-D to return to the `:)` prompt. The unhandled Dart | 39 "file". You can press Control-D to return to the `:)` prompt. The unhandled Dart |
36 exception after you press Control-D is definitely a bug.) | 40 exception after you press Control-D is definitely a bug.) |
37 | 41 |
38 Another example you may try is: | 42 ### Example 2: Running native console applications |
| 43 |
| 44 The `native_support` service supports running native (Linux) applications. The |
| 45 `native_run_app` application provides a terminal client front-end: |
| 46 |
| 47 :) mojo:native_run_app |
| 48 |
| 49 At its `>>>` prompt, you can enter name of a native application. E.g.: |
| 50 |
| 51 >>> bash |
| 52 $ echo hello linux |
| 53 hello linux |
| 54 $ |
| 55 |
| 56 ### Example 3: JavaScript REPL |
| 57 |
| 58 A terminal client application (written in JavaScript, using the JavaScript |
| 59 content handler) that provides a JavaScript REPL: |
39 | 60 |
40 :) file:///path/to/src/examples/js/repl.js | 61 :) file:///path/to/src/examples/js/repl.js |
41 | 62 |
42 At its `>` prompt, you can enter JavaScript expressions. E.g.: | 63 At its `>` prompt, you can enter JavaScript expressions. E.g.: |
43 | 64 |
44 > function add(x, y) { return x + y; } | 65 > function add(x, y) { return x + y; } |
45 undefined | 66 undefined |
46 > add("hello ", 123) | 67 > add("hello ", 123) |
47 "hello 123" | 68 "hello 123" |
| 69 > |
48 | 70 |
49 ## See also | 71 ## See also |
50 | 72 |
51 * [//apps/moterm](../../apps/moterm) | 73 * [//apps/moterm](../../apps/moterm) |
52 * [//examples/dart/netcat](../dart/netcat) | 74 * [//examples/dart/netcat](../dart/netcat) |
| 75 * [//examples/native_run_app](../native_run_app) |
53 * [//examples/js/repl.js](../js/repl.js) | 76 * [//examples/js/repl.js](../js/repl.js) |
OLD | NEW |