Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/terminal/TerminalWidget.js

Issue 2372303003: DevTools: introduce external service client (behind experiment). (Closed)
Patch Set: external linter Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 */
9 WebInspector.TerminalWidget = function()
10 {
11 WebInspector.VBox.call(this, false);
12 this.registerRequiredCSS("terminal/xterm.js/build/xterm.css");
13 this.registerRequiredCSS("terminal/terminal.css");
14 this.element.classList.add("terminal-root");
15 this.element.addEventListener("mousemove", this._mouseMove.bind(this), false );
16 this._init();
17 this._linkifier = new WebInspector.Linkifier();
18 this._linkifyFunction = this._linkifyURL.bind(this);
19 }
20
21 WebInspector.TerminalWidget.prototype = {
22 _init: function()
23 {
24 WebInspector.serviceManager.createService("Terminal").then(this._initial ized.bind(this));
25 },
26
27 /**
28 * @param {?WebInspector.ServiceManager.Service} backend
29 */
30 _initialized: function(backend)
31 {
32 if (!backend) {
33 if (!this._unavailableLabel) {
34 this._unavailableLabel = this.element.createChild("div", "termin al-error-message fill");
35 this._unavailableLabel.createChild("div").textContent = WebInspe ctor.UIString("Terminal service is not available");
36 }
37 if (this.isShowing())
38 setTimeout(this._init.bind(this), 2000);
39 return;
40 }
41
42 if (this._unavailableLabel) {
43 this._unavailableLabel.remove();
44 delete this._unavailableLabel;
45 }
46
47 this._backend = backend;
48
49 if (!this._term) {
50 this._term = new Terminal({ cursorBlink: true });
51 this._term.open(this.contentElement);
52 this._term.on("data", data => {
53 this._backend.send("write", { data: data });
54 });
55 this._term.fit();
56 this._term.on("resize", size => {
57 this._backend.send("resize", { cols: size.cols, rows: size.rows });
58 });
59 }
60
61 this._backend.send("init", { cols: this._term.cols, rows: this._term.row s });
62 this._backend.on("data", result => {
63 this._term.write(result.data);
64 this._linkifyUpToDate = false;
65 });
66 this._backend.on("disposed", this._disposed.bind(this));
67 },
68
69 _mouseMove: function()
70 {
71 if (this._linkifyUpToDate)
72 return;
73 if (this._term)
74 this._linkify();
75 this._linkifyUpToDate = true;
76 },
77
78 onResize: function()
79 {
80 if (this._term)
81 this._term.fit();
82 },
83
84 _disposed: function()
85 {
86 this._initialized(null);
87 },
88
89 /**
90 * @override
91 */
92 wasDetachedFromHierarchy: function()
93 {
94 if (this._backend)
95 this._backend.dispose();
96 },
97
98 _linkify: function()
99 {
100 if (!this._term)
101 return;
102 this._linkifier.reset();
103 var rows = this._term.rowContainer.children;
104 for (var i = 0; i < rows.length; i++)
105 this._linkifyTerminalLine(rows[i]);
106 },
107
108 /**
109 * @param {!Node} line
110 */
111 _linkifyTerminalLine: function(line)
112 {
113 var node = line.firstChild;
114 while (node) {
115 if (node.nodeType !== Node.TEXT_NODE) {
116 node = node.nextSibling;
117 continue;
118 }
119 var nextNode = node.nextSibling;
120 node.remove();
121 var linkified = WebInspector.linkifyStringAsFragmentWithCustomLinkif ier(node.textContent, this._linkifyFunction);
122 line.insertBefore(linkified, nextNode);
123 node = nextNode;
124 }
125 },
126
127 /**
128 * @param {string} title
129 * @param {string} url
130 * @param {number=} lineNumber
131 * @param {number=} columnNumber
132 */
133 _linkifyURL: function(title, url, lineNumber, columnNumber)
134 {
135 return this._linkifier.linkifyScriptLocation(null, null, url, lineNumber || 0, columnNumber || 0);
136 },
137
138 __proto__: WebInspector.VBox.prototype
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698