Make the terminal demo able (to try) to connect to anything.
(Using the query string from the URL.) R=erg@chromium.org Review URL: https://codereview.chromium.org/1019323002
This commit is contained in:
parent
bd7603bdb0
commit
818df5f4c6
@ -5,4 +5,22 @@
|
||||
// found in the LICENSE file.
|
||||
-->
|
||||
<import src="terminal.sky" />
|
||||
<terminal url="mojo:echo_terminal" />
|
||||
<!--
|
||||
<terminal id="terminal" url="mojo:echo_terminal" />
|
||||
-->
|
||||
<terminal id="terminal" />
|
||||
<script>
|
||||
import 'dart:core';
|
||||
import 'dart:sky';
|
||||
|
||||
main () {
|
||||
var terminal = document.getElementById('terminal');
|
||||
var params = Uri.parse(document.URL).queryParameters;
|
||||
if (params.containsKey('url')) {
|
||||
terminal.connect(params['url']);
|
||||
} else {
|
||||
terminal.putString('HALP: Add a "?url=<URL>" query.\n'
|
||||
'E.g., "?url=mojo:echo_terminal".\n');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -13,9 +13,10 @@
|
||||
background-color: black;
|
||||
color: rgb(255, 191, 0);
|
||||
font-family: 'Courier', 'monospace';
|
||||
font-size: small;
|
||||
}
|
||||
.line {
|
||||
white-space: pre;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
<sky-scrollable id="control" contenteditable />
|
||||
@ -60,7 +61,10 @@ class TerminalDisplayImpl extends SkyElement implements TerminalDisplay {
|
||||
// Initialize with the first line.
|
||||
_newLine();
|
||||
|
||||
_connect(getAttribute('url'));
|
||||
var url = getAttribute('url');
|
||||
if (url != null) {
|
||||
connect(url);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleKeyDown(KeyboardEvent event) {
|
||||
@ -111,15 +115,19 @@ class TerminalDisplayImpl extends SkyElement implements TerminalDisplay {
|
||||
_newLine();
|
||||
}
|
||||
|
||||
// TODO(vtl): Should we always auto-connect? Should there be facilities for
|
||||
// programmatically connecting? (What if the |url| attribute isn't set?)
|
||||
void _connect(String url) {
|
||||
void connect(String url) {
|
||||
var terminalClient = new terminal.TerminalClientProxy.unbound();
|
||||
embedder.connectToService(url, terminalClient);
|
||||
terminalClient.ptr.connectToTerminal(new TerminalFileImpl(this).stub);
|
||||
terminalClient.close();
|
||||
}
|
||||
|
||||
void putString(String s) {
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
putChar(s.codeUnitAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
// |TerminalDisplay| implementation:
|
||||
|
||||
@override
|
||||
|
Loading…
x
Reference in New Issue
Block a user