blob: 85716cc0eabed7da7142e94e742d9cb820e993c3 [file] [log] [blame] [view]
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -07001# 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 Luubcddefb2015-10-09 09:39:54 -07005connected to other applications (which should provide the
6`mojo.terminal.TerminalClient` service).
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -07007
8## Running
9
10On Linux, run it in the usual way, e.g.:
11
Jeff Brown5a846ea2016-01-26 15:53:07 -080012 $ mojo/devtools/common/mojo_run --enable-multiprocess \
13 "mojo:launcher mojo:moterm_example_app"
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -070014
15You'll probably need to click on the window to give it keyboard focus. You may
16also want to resize the window (especially horizontally) to make it bigger.
17
Viet-Trung Luubcddefb2015-10-09 09:39:54 -070018At the `:)` prompt, you may enter the URL for any application providing the
19`mojo.terminal.TerminalClient` service.
20
21### Example 1: Dart netcat
22
23An example of a terminal client application written in Dart is `dart_netcat`:
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -070024
25 :) mojo:dart_netcat
26
27At this point, the terminal's input/output is transferred to the specified
28application. In this case, it just outputs a help message and closes the
29terminal, returning you to the `:)` prompt. You may also try:
30
31 :) mojo:dart_netcat?localhost&port=80
32
33In this case, `mojo:dart_netcat` will make a TCP connection to the specified
34host/port. Assuming you have a web server running on your machine, you may try
35entering:
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
41exception after you press Control-D is definitely a bug.)
42
Viet-Trung Luubcddefb2015-10-09 09:39:54 -070043### Example 2: Running native console applications
44
45The `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
50At 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
59A terminal client application (written in JavaScript, using the JavaScript
60content handler) that provides a JavaScript REPL:
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -070061
62 :) file:///path/to/src/examples/js/repl.js
63
64At 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 Luubcddefb2015-10-09 09:39:54 -070070 >
Viet-Trung Luu7ba2beb2015-09-10 14:26:52 -070071
72## See also
73
74* [//apps/moterm](../../apps/moterm)
75* [//examples/dart/netcat](../dart/netcat)
Viet-Trung Luubcddefb2015-10-09 09:39:54 -070076* [//examples/native_run_app](../native_run_app)
Viet-Trung Luuedd91fd2015-09-10 14:30:01 -070077* [//examples/js/repl.js](../js/repl.js)