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