OLD | NEW |
1 <!-- | 1 <!-- |
2 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 --> | 5 --> |
6 <import src="/sky/framework/elements/sky-element.sky" /> | 6 <import src="/sky/framework/elements/sky-element.sky" /> |
7 <import src="/sky/framework/elements/sky-scrollable.sky" /> | 7 <import src="/sky/framework/elements/sky-scrollable.sky" /> |
8 <sky-element> | 8 <sky-element> |
9 <template> | 9 <template> |
10 <style> | 10 <style> |
11 #control { | 11 #control { |
12 height: -webkit-fill-available; | 12 height: -webkit-fill-available; |
13 background-color: black; | 13 background-color: black; |
14 color: rgb(255, 191, 0); | 14 color: rgb(255, 191, 0); |
15 font-family: 'Courier', 'monospace'; | 15 font-family: 'Courier', 'monospace'; |
| 16 font-size: small; |
16 } | 17 } |
17 .line { | 18 .line { |
18 white-space: pre; | 19 white-space: nowrap; |
19 } | 20 } |
20 </style> | 21 </style> |
21 <sky-scrollable id="control" contenteditable /> | 22 <sky-scrollable id="control" contenteditable /> |
22 </template> | 23 </template> |
23 <script> | 24 <script> |
24 import 'dart:async'; | 25 import 'dart:async'; |
25 import 'dart:core'; | 26 import 'dart:core'; |
26 import 'dart:sky'; | 27 import 'dart:sky'; |
27 import 'package:mojo/services/terminal/public/interfaces/terminal_client.mojom.d
art' as terminal; | 28 import 'package:mojo/services/terminal/public/interfaces/terminal_client.mojom.d
art' as terminal; |
28 import 'package:sky/framework/embedder.dart'; | 29 import 'package:sky/framework/embedder.dart'; |
(...skipping 24 matching lines...) Expand all Loading... |
53 } | 54 } |
54 | 55 |
55 void shadowRootReady() { | 56 void shadowRootReady() { |
56 _control = shadowRoot.getElementById('control'); | 57 _control = shadowRoot.getElementById('control'); |
57 _control.addEventListener('keydown', _handleKeyDown); | 58 _control.addEventListener('keydown', _handleKeyDown); |
58 _control.addEventListener('keypress', _handleKeyPress); | 59 _control.addEventListener('keypress', _handleKeyPress); |
59 | 60 |
60 // Initialize with the first line. | 61 // Initialize with the first line. |
61 _newLine(); | 62 _newLine(); |
62 | 63 |
63 _connect(getAttribute('url')); | 64 var url = getAttribute('url'); |
| 65 if (url != null) { |
| 66 connect(url); |
| 67 } |
64 } | 68 } |
65 | 69 |
66 void _handleKeyDown(KeyboardEvent event) { | 70 void _handleKeyDown(KeyboardEvent event) { |
67 // TODO(vtl): In general, our key handling is a total hack (due in part to | 71 // TODO(vtl): In general, our key handling is a total hack (due in part to |
68 // sky's keyboard support being incomplete) -- e.g., we shouldn't have to | 72 // sky's keyboard support being incomplete) -- e.g., we shouldn't have to |
69 // make our div contenteditable. We have to intercept backspace (^H) here, | 73 // make our div contenteditable. We have to intercept backspace (^H) here, |
70 // since we won't actually get a keypress event for it. (Possibly, we should | 74 // since we won't actually get a keypress event for it. (Possibly, we should |
71 // only handle keydown instead of keypress, but then we'd have to handle | 75 // only handle keydown instead of keypress, but then we'd have to handle |
72 // shift, etc. ourselves.) | 76 // shift, etc. ourselves.) |
73 if (event.key == 8) { | 77 if (event.key == 8) { |
(...skipping 30 matching lines...) Expand all Loading... |
104 _control.appendChild(line); | 108 _control.appendChild(line); |
105 } | 109 } |
106 | 110 |
107 void _clear() { | 111 void _clear() { |
108 while (_control.firstChild != null) { | 112 while (_control.firstChild != null) { |
109 _control.firstChild.remove(); | 113 _control.firstChild.remove(); |
110 } | 114 } |
111 _newLine(); | 115 _newLine(); |
112 } | 116 } |
113 | 117 |
114 // TODO(vtl): Should we always auto-connect? Should there be facilities for | 118 void connect(String url) { |
115 // programmatically connecting? (What if the |url| attribute isn't set?) | |
116 void _connect(String url) { | |
117 var terminalClient = new terminal.TerminalClientProxy.unbound(); | 119 var terminalClient = new terminal.TerminalClientProxy.unbound(); |
118 embedder.connectToService(url, terminalClient); | 120 embedder.connectToService(url, terminalClient); |
119 terminalClient.ptr.connectToTerminal(new TerminalFileImpl(this).stub); | 121 terminalClient.ptr.connectToTerminal(new TerminalFileImpl(this).stub); |
120 terminalClient.close(); | 122 terminalClient.close(); |
121 } | 123 } |
122 | 124 |
| 125 void putString(String s) { |
| 126 for (var i = 0; i < s.length; i++) { |
| 127 putChar(s.codeUnitAt(i)); |
| 128 } |
| 129 } |
| 130 |
123 // |TerminalDisplay| implementation: | 131 // |TerminalDisplay| implementation: |
124 | 132 |
125 @override | 133 @override |
126 void putChar(int byte) { | 134 void putChar(int byte) { |
127 // Fast-path for printable chars. | 135 // Fast-path for printable chars. |
128 if (byte >= 32) { | 136 if (byte >= 32) { |
129 _control.lastChild.textContent += new String.fromCharCode(byte); | 137 _control.lastChild.textContent += new String.fromCharCode(byte); |
130 return; | 138 return; |
131 } | 139 } |
132 | 140 |
(...skipping 24 matching lines...) Expand all Loading... |
157 | 165 |
158 var completer = new Completer<int>(); | 166 var completer = new Completer<int>(); |
159 _readerQueue.add(completer); | 167 _readerQueue.add(completer); |
160 return completer.future; | 168 return completer.future; |
161 } | 169 } |
162 } | 170 } |
163 | 171 |
164 _init(script) => register(script, TerminalDisplayImpl); | 172 _init(script) => register(script, TerminalDisplayImpl); |
165 </script> | 173 </script> |
166 </sky-element> | 174 </sky-element> |
OLD | NEW |