antosdk-apps/vTerm/build/debug/main.js

167 lines
296 KiB
JavaScript
Raw Normal View History

2020-08-06 23:21:42 +02:00
(function() {
// 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
//along with this program. If not, see https://www.gnu.org/licenses/
var vTerm;
vTerm = class vTerm extends this.OS.application.BaseApplication {
constructor(args) {
super("vTerm", 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.sub) {
return;
}
return this.sub.send(Antunnel.Msg.DATA, new TextEncoder("utf-8").encode(d.key));
});
this.sub = void 0;
this.on("focus", () => {
return this.term.focus();
});
this.mterm.contextmenuHandle = (e, m) => {
m.items = [
{
text: "__(Copy)",
id: "copy"
},
{
text: "__(Paste)",
id: "paste"
}
];
m.onmenuselect = (e) => {
if (!e) {
return;
}
return this.mctxHandle(e.data.item.data);
};
return m.show(e);
};
this.resizeContent();
if (!this.systemsetting.desktop.menu[this.name]) {
// make desktop menu if not exist
this.systemsetting.desktop.menu[this.name] = {
text: "__(Open terminal)",
app: "vTerm"
};
}
this.on("hboxchange", (e) => {
return this.resizeContent();
});
if (!Antunnel.tunnel) {
this.error(__("The Antunnel service is not started, please start it first"));
this._gui.pushService("Antunnel/AntunnelService").catch((e) => {
return this.error(e.toString(), e);
});
return this.quit();
} else {
this.tunnel = Antunnel.tunnel;
return this.openSession();
}
}
mctxHandle(data) {
var text;
switch (data.id) {
case "paste":
return this._api.getClipboard().then((text) => {
if (!(text && text !== "")) {
return;
}
if (this.sub) {
return this.sub.send(Antunnel.Msg.DATA, new TextEncoder("utf-8").encode(text));
}
}).catch((e) => {
return this.error(__("Unable to paste"), e);
});
case "copy":
text = this.term.getSelection();
if (!(text && text !== "")) {
return;
}
return this._api.setClipboard(text);
}
}
resizeContent() {
var arr, ncol, nrow;
this.fitAddon.fit();
ncol = this.term.cols;
nrow = this.term.rows;
if (!this.sub) {
return;
}
arr = new Uint8Array(8);
arr.set(Antunnel.Msg.bytes_of(ncol), 0);
arr.set(Antunnel.Msg.bytes_of(nrow), 4);
return this.sub.send(Antunnel.Msg.CTRL, arr);
}
openSession() {
this.term.clear();
this.term.focus();
this.sub = new Antunnel.Subscriber("vterm");
this.sub.onopen = () => {
console.log("Subscribed");
this.resizeContent(($(this.mterm)).width(), ($(this.mterm)).height());
return this.term.focus();
};
this.sub.onerror = (e) => {
this.error(__("Unable to connect to: vterm"), e);
return this.sub = void 0;
};
this.sub.onmessage = (e) => {
if (this.term && e.data) {
return this.term.write(new TextDecoder("utf-8").decode(e.data));
}
};
this.sub.onclose = () => {
this.sub = void 0;
this.notify(__("Terminal connection closed"));
return this.quit();
};
return this.tunnel.subscribe(this.sub);
}
cleanup(e) {
if (this.sub) {
return this.sub.close();
}
}
};
vTerm.dependencies = ["pkg://Antunnel/main.js"];
this.OS.register("vTerm", vTerm);
}).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