2020-05-20 23:13:28 +02:00
|
|
|
(function() {
|
|
|
|
void 0;
|
2020-05-21 17:28:02 +02:00
|
|
|
var wTerm;
|
2020-05-20 23:13:28 +02:00
|
|
|
|
|
|
|
// Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
|
|
|
|
|
|
|
|
// AnTOS Web desktop is is licensed under the GNU General Public
|
|
|
|
// License v3.0, see the LICENCE file for more information
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-05-21 17:28:02 +02:00
|
|
|
//along with this program. If not, see https://www.gnu.org/licenses/
|
2020-05-20 23:13:28 +02:00
|
|
|
wTerm = class wTerm extends this.OS.GUI.BaseApplication {
|
|
|
|
constructor(args) {
|
|
|
|
super("wTerm", args);
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
this.mterm = this.find("myterm");
|
|
|
|
this.term = new Terminal({
|
|
|
|
cursorBlink: true
|
|
|
|
});
|
|
|
|
this.fitAddon = new FitAddon.FitAddon();
|
|
|
|
this.term.loadAddon(this.fitAddon);
|
|
|
|
this.term.setOption('fontSize', '12');
|
|
|
|
this.term.open(this.mterm);
|
|
|
|
this.term.onKey((d) => {
|
|
|
|
if (this.socket) {
|
|
|
|
return this.socket.send(`i${d.key}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.socket = void 0;
|
|
|
|
this.on("focus", () => {
|
|
|
|
return this.term.focus();
|
|
|
|
});
|
|
|
|
this.mterm.contextmenuHandle = (e, m) => {
|
|
|
|
m.set("items", [
|
|
|
|
{
|
|
|
|
text: "__(Copy)",
|
|
|
|
id: "copy"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "__(Paste)",
|
|
|
|
id: "paste"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
m.set("onmenuselect", (e) => {
|
|
|
|
if (!e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return this.mctxHandle(e.data.item.get("data"));
|
|
|
|
});
|
|
|
|
return m.show(e);
|
|
|
|
};
|
2020-05-21 22:34:35 +02:00
|
|
|
this.resizeContent();
|
2020-05-20 23:13:28 +02:00
|
|
|
this.openSession();
|
|
|
|
if (!this.systemsetting.desktop.menu[this.name]) {
|
|
|
|
|
|
|
|
// make desktop menu if not exist
|
|
|
|
this.systemsetting.desktop.menu[this.name] = {
|
|
|
|
text: "__(Open terminal)",
|
|
|
|
app: "wTerm"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return this.on("hboxchange", (e) => {
|
|
|
|
return this.resizeContent();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
mctxHandle(data) {
|
|
|
|
var text;
|
|
|
|
switch (data.id) {
|
|
|
|
case "paste":
|
2020-05-21 17:28:02 +02:00
|
|
|
return this._api.getClipboard().then((text) => {
|
2020-05-20 23:13:28 +02:00
|
|
|
var i, len, results, v;
|
2020-05-21 17:28:02 +02:00
|
|
|
if (!(text && text !== "")) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-20 23:13:28 +02:00
|
|
|
results = [];
|
2020-05-21 17:28:02 +02:00
|
|
|
for (i = 0, len = text.length; i < len; i++) {
|
|
|
|
v = text[i];
|
2020-05-20 23:13:28 +02:00
|
|
|
results.push(this.socket.send(`i${v}`));
|
|
|
|
}
|
|
|
|
return results;
|
2020-05-21 17:28:02 +02:00
|
|
|
}).catch((e) => {
|
|
|
|
return this.error(__("Unable to paste"), e);
|
2020-05-20 23:13:28 +02:00
|
|
|
});
|
|
|
|
case "copy":
|
|
|
|
text = this.term.getSelection();
|
|
|
|
if (!(text && text !== "")) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-21 17:28:02 +02:00
|
|
|
return this._api.setClipboard(text);
|
2020-05-20 23:13:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resizeContent() {
|
|
|
|
var ncol, nrow;
|
|
|
|
this.fitAddon.fit();
|
|
|
|
ncol = this.term.cols;
|
|
|
|
nrow = this.term.rows;
|
2020-05-21 22:34:35 +02:00
|
|
|
if (!this.socket) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-20 23:13:28 +02:00
|
|
|
return this.socket.send(`s${ncol}:${nrow}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
openSession() {
|
|
|
|
this.term.clear();
|
|
|
|
this.term.focus();
|
|
|
|
console.log(this.setting.uri);
|
|
|
|
if (!this.setting.uri) {
|
|
|
|
return this.configure();
|
|
|
|
}
|
|
|
|
this.socket = new WebSocket(this.setting.uri);
|
|
|
|
this.socket.onopen = () => {
|
|
|
|
this.resizeContent(($(this.mterm)).width(), ($(this.mterm)).height());
|
|
|
|
return this.term.focus();
|
|
|
|
};
|
|
|
|
this.socket.onerror = (e) => {
|
|
|
|
this.error(__("Unable to connect to: {0}", this.setting.uri), e);
|
|
|
|
return this.socket = void 0;
|
|
|
|
};
|
|
|
|
this.socket.onmessage = (e) => {
|
|
|
|
if (this.term && e.data) {
|
|
|
|
return this.term.write(e.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return this.socket.onclose = () => {
|
|
|
|
this.socket = void 0;
|
|
|
|
return this.notify(__("Terminal connection closed"));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup(e) {
|
|
|
|
if (this.socket) {
|
|
|
|
return this.socket.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu() {
|
|
|
|
return {
|
|
|
|
text: "__(Edit)",
|
|
|
|
child: [
|
|
|
|
{
|
|
|
|
text: "__(Terminal URI)",
|
|
|
|
dataid: `${this.name}-termuri`
|
|
|
|
}
|
|
|
|
],
|
|
|
|
onchildselect: (e) => {
|
|
|
|
return this.configure();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
configure() {
|
|
|
|
if (this.socket) {
|
|
|
|
this.socket.close();
|
|
|
|
}
|
|
|
|
return this.openDialog("PromptDialog", {
|
|
|
|
title: "__(Please enter terminal URI)",
|
|
|
|
label: "__(URI)",
|
|
|
|
value: this.setting.uri || "wss://lxsang.me/wterm"
|
|
|
|
}).then((d) => {
|
|
|
|
if (!(d && d !== "")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setting.uri = d;
|
|
|
|
return this.openSession();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.OS.register("wTerm", wTerm);
|
|
|
|
|
|
|
|
}).call(this);
|
|
|
|
|
|
|
|
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FitAddon=t():e.FitAddon=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0;var n=function(){function e(){}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.fit=function(){var e=this.proposeDimensions();if(e&&this._terminal){var t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}},e.prototype.proposeDimensions=function(){if(this._terminal&&this._terminal.element&&this._terminal.element.parentElement){var e=this._terminal._core,t=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(t.getPropertyValue("height")),n=Math.max(0,parseInt(t.getPropertyValue("width"))),o=window.getComputedStyle(this._terminal.element),i=r-(parseInt(o.getPropertyValue("padding-top"))+parseInt(o.getPropertyValue("padding-bottom"))),a=n-(parseInt(o.getPropertyValue("padding-right"))+parseInt(o.getPropertyValue("padding-left")))-e.viewport.scrollBarWidth;return{cols:Math.max(2,Math.floor(a/e._renderService.dimensions.actualCellWidth)),rows:Math.max(1,Math.floor(i/e._renderService.dimensions.actualCellHeight))}}},e}();t.FitAddon=n}])}));
|
|
|
|
//# sourceMappingURL=xterm-addon-fit.js.map
|
|
|
|
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(window,(function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=33)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.forwardEvent=t.EventEmitter=void 0;var i=function(){function e(){this._listeners=[],this._disposed=!1}return Object.defineProperty(e.prototype,"event",{get:function(){var e=this;return this._event||(this._event=function(t){return e._listeners.push(t),{dispose:function(){if(!e._disposed)for(var r=0;r<e._listeners.length;r++)if(e._listeners[r]===t)return void e._listeners.splice(r,1)}}}),this._event},enumerable:!1,configurable:!0}),e.prototype.fire=function(e,t){for(var r=[],i=0;i<this._listeners.length;i++)r.push(this._listeners[i]);for(i=0;i<r.length;i++)r[i].call(void 0,e,t)},e.prototype.dispose=function(){this._listeners&&(this._listeners.length=0),this._disposed=!0},e}();t.EventEmitter=i,t.forwardEvent=function(e,t){return e((function(e){return t.fire(e)}))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.IUnicodeService=t.IOptionsService=t.ILogService=t.IInstantiationService=t.IDirtyRowService=t.ICharsetService=t.ICoreService=t.ICoreMouseService=t.IBufferService=void 0;var i=r(14);t.IBufferService=i.createDecorator("BufferService"),t.ICoreMouseService=i.createDecorator("CoreMouseService"),t.ICoreService=i.createDecorator("CoreService"),t.ICharsetService=i.createDecorator("CharsetService"),t.IDirtyRowService=i.createDecorator("DirtyRowService"),t.IInstantiationService=i.createDecorator("InstantiationService"),t.ILogService=i.createDecorator("LogService"),t.IOptionsService=i.createDecorator("OptionsService"),t.IUnicodeService=i.createDecorator("UnicodeService")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getDisposeArrayDisposable=t.disposeArray=t.Disposable=void 0;var i=function(){function e(){this._disposables=[],this._isDisposed=!1}return e.prototype.dispose=function(){this._isDisposed=!0,this._disposables.forEach((function(e){return e.dispose()})),this._disposables.length=0},e.prototype.register=function(e){return this._disposables.push(e),e},e.prototype.unregister=function(e){var t=this._disposables.indexOf(e);-1!==t&&this._disposables.splice(t,1)},e}();function n(e){e.forEach((function(e){return e.dispose()})),e.length=0}t.Disposable=i,t.disposeArray=n,t.getDisposeArrayDisposable=function(e){return{dispose:function(){return n(e)}}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WHITESPACE_CELL_CODE=t.WHITESPACE_CELL_WIDTH=t.WHITESPACE_CELL_CHAR=t.NULL_CELL_CODE=t.NULL_CELL_WIDTH=t.NULL_CELL_CHAR=t.CHAR_DATA_CODE_INDEX=t.CHAR_DATA_WIDTH_INDEX=t.CHAR_DATA_CHAR_INDEX=t.CHAR_DATA_ATTR_INDEX=t.DEFAULT_ATTR=t.DEFAULT_COLOR=void 0,t.DEFAULT_COLOR=256,t.DEFAULT_ATTR=256|t.DEFAULT_COLOR<<9,t.CHAR_DATA_ATTR_INDEX=0,t.CHAR_DATA_CHAR_INDEX=1,t.CHAR_DATA_WIDTH_INDEX=2,t.CHAR_DATA_CODE_INDEX=3,t.NULL_CELL_CHAR="",t.NULL_CELL_WIDTH=1,t.NULL_CELL_CODE=0,t.WHITESPACE_CELL_CHAR=" ",t.WHITESPACE_CELL_WIDTH
|
|
|
|
//# sourceMappingURL=xterm.js.map
|