@difizen/libro-terminal 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/view.js CHANGED
@@ -1,14 +1,24 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
2
+ var _dec, _dec2, _class;
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3
12
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
13
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
14
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
- function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
7
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
16
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
17
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
18
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
19
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
21
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
12
22
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
23
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -16,55 +26,51 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
16
26
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
27
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
28
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
20
- function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
21
29
  import { CodeOutlined } from '@ant-design/icons';
22
- import { isFirefox } from '@difizen/mana-app';
23
- import { BaseView, view, transient, inject, Disposable, KeyCode, isOSX, DisposableCollection, Emitter } from '@difizen/mana-app';
30
+ import { Disposable, DisposableCollection, Emitter, KeyCode, ViewInstance, ViewOption, inject, isFirefox, isOSX, transient, useInject, view } from '@difizen/mana-app';
24
31
  import { forwardRef } from 'react';
25
32
  import { Terminal } from 'xterm';
33
+ import { CanvasAddon } from 'xterm-addon-canvas';
26
34
  import { FitAddon } from 'xterm-addon-fit';
27
- import { DEFAULT_TERMINAL_RENDERER_TYPE, isTerminalRendererType } from "./configuration.js";
28
- import { TerminalConfiguration } from "./configuration.js";
35
+ import { WebLinksAddon } from 'xterm-addon-web-links';
36
+ import { WebglAddon } from 'xterm-addon-webgl';
37
+ import { DEFAULT_TERMINAL_RENDERER_TYPE, TerminalConfiguration, isTerminalRendererType } from "./configuration.js";
29
38
  import { TerminalManager } from "./manager.js";
30
- import { TerminalViewOption } from "./protocol.js";
39
+ import 'xterm/css/xterm.css';
40
+ import { BaseStatefulView } from "./stateful-view.js";
31
41
  import { TerminalThemeService } from "./theme-service.js";
32
42
  import { jsx as _jsx } from "react/jsx-runtime";
33
43
  export var TerminalComponent = /*#__PURE__*/forwardRef(function TerminalComponent(_props, ref) {
34
- // const instance = useInject<LibroTerminalView>(ViewInstance);
44
+ var instance = useInject(ViewInstance);
35
45
  return /*#__PURE__*/_jsx("div", {
36
- tabIndex: 1,
46
+ id: instance.id
47
+ // tabIndex={1}
48
+ ,
37
49
  className: "libro-terminal",
38
- ref: ref,
39
- children: "/"
50
+ ref: ref
40
51
  });
41
52
  });
42
- export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal-view'), _dec3 = inject(TerminalConfiguration), _dec4 = inject(TerminalThemeService), _dec5 = inject(TerminalManager), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
43
- _inherits(LibroTerminalView, _BaseView);
53
+ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal-view'), _dec(_class = _dec2(_class = /*#__PURE__*/function (_BaseStatefulView) {
54
+ _inherits(LibroTerminalView, _BaseStatefulView);
44
55
  var _super = _createSuper(LibroTerminalView);
45
- function LibroTerminalView(options) {
56
+ function LibroTerminalView(_options, config, themeService, terminalManager) {
46
57
  var _this;
47
58
  _classCallCheck(this, LibroTerminalView);
48
59
  _this = _super.call(this);
49
60
  _this.view = TerminalComponent;
50
61
  _this.termOpened = false;
51
62
  _this.initialData = '';
52
- _initializerDefineProperty(_this, "config", _descriptor, _assertThisInitialized(_this));
53
- _initializerDefineProperty(_this, "themeService", _descriptor2, _assertThisInitialized(_this));
54
- _initializerDefineProperty(_this, "terminalManager", _descriptor3, _assertThisInitialized(_this));
55
63
  _this.toDisposeOnConnect = new DisposableCollection();
56
64
  _this.onDidOpenEmitter = new Emitter();
57
65
  _this.onDidOpen = _this.onDidOpenEmitter.event;
58
66
  _this.onDidOpenFailureEmitter = new Emitter();
59
- _this.onDidOpenFailure = _this.onDidOpenFailureEmitter.event;
60
67
  _this.onSizeChangedEmitter = new Emitter();
61
- _this.onSizeChanged = _this.onSizeChangedEmitter.event;
62
68
  _this.onDataEmitter = new Emitter();
63
- _this.onData = _this.onDataEmitter.event;
64
69
  _this.onKeyEmitter = new Emitter();
65
- _this.onKey = _this.onKeyEmitter.event;
66
70
  _this.onDidCloseEmitter = new Emitter();
67
- _this.onDidClose = _this.onDidCloseEmitter.event;
71
+ _this.onTitleChangeEmitter = new Emitter();
72
+ _this._isReady = false;
73
+ _this.onReadyEmitter = new Emitter();
68
74
  _this.createConnection = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
69
75
  var connection;
70
76
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -74,24 +80,42 @@ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal
74
80
  return _this.terminalManager.getOrCreate(_this.options);
75
81
  case 2:
76
82
  connection = _context.sent;
77
- _this.connection = connection;
78
- connection.messageReceived(_this.onMessage);
79
- if (!_this.isDisposed) {
80
- _context.next = 7;
81
- break;
82
- }
83
- return _context.abrupt("return");
84
- case 7:
85
- _this.initialConnection();
86
- _this.toDispose.push(connection.connectionStatusChanged(_this.initialConnection));
87
- case 9:
83
+ return _context.abrupt("return", connection);
84
+ case 4:
88
85
  case "end":
89
86
  return _context.stop();
90
87
  }
91
88
  }, _callee);
92
89
  }));
90
+ /**
91
+ * Handle a message from the terminal session.
92
+ */
93
+ _this.onMessage = function (msg) {
94
+ switch (msg.type) {
95
+ case 'stdout':
96
+ if (msg.content) {
97
+ _this.term.write(msg.content[0]);
98
+ }
99
+ break;
100
+ case 'disconnect':
101
+ _this.term.write('\r\n\r\n[Finished… Term Session]\r\n');
102
+ break;
103
+ default:
104
+ break;
105
+ }
106
+ };
107
+ // 设置初始命令
108
+ _this.initialCommand = function () {
109
+ if (_this.connection && _this.options.initialCommand) {
110
+ var _this$connection;
111
+ (_this$connection = _this.connection) === null || _this$connection === void 0 || _this$connection.send({
112
+ type: 'stdin',
113
+ content: [_this.options.initialCommand + '\r']
114
+ });
115
+ }
116
+ };
93
117
  _this.createTerm = function () {
94
- var term = new Terminal({
118
+ var options = {
95
119
  cursorBlink: _this.config.get('terminal.integrated.cursorBlinking'),
96
120
  cursorStyle: _this.getCursorStyle(),
97
121
  cursorWidth: _this.config.get('terminal.integrated.cursorWidth'),
@@ -105,18 +129,18 @@ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal
105
129
  scrollback: _this.config.get('terminal.integrated.scrollback'),
106
130
  fastScrollSensitivity: _this.config.get('terminal.integrated.fastScrollSensitivity'),
107
131
  rendererType: _this.getTerminalRendererType(_this.config.get('terminal.integrated.rendererType')),
108
- theme: _this.themeService.theme
109
- });
110
- var fitAddon = new FitAddon();
111
- term.loadAddon(fitAddon);
132
+ theme: _this.themeService.getTheme()
133
+ };
134
+ var _this$createTerminal = _this.createTerminal(options),
135
+ _this$createTerminal2 = _slicedToArray(_this$createTerminal, 2),
136
+ term = _this$createTerminal2[0],
137
+ fitAddon = _this$createTerminal2[1];
112
138
  _this.fitAddon = fitAddon;
113
139
  _this.term = term;
114
- _this.term.attachCustomKeyEventHandler(function (e) {
115
- return _this.customKeyHandler(e);
116
- });
117
140
  };
118
141
  _this.customKeyHandler = function (event) {
119
- var keyBindings = KeyCode.createKeyCode(event).toString();
142
+ var keycode = KeyCode.createKeyCode(event);
143
+ var keyBindings = keycode.toString();
120
144
  var ctrlCmdCopy = isOSX && keyBindings === 'meta+c' || !isOSX && keyBindings === 'ctrl+c';
121
145
  var ctrlCmdPaste = isOSX && keyBindings === 'meta+v' || !isOSX && keyBindings === 'ctrl+v';
122
146
  if (ctrlCmdCopy && _this.enableCopy && _this.term.hasSelection()) {
@@ -146,41 +170,85 @@ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal
146
170
  }
147
171
  return DEFAULT_TERMINAL_RENDERER_TYPE;
148
172
  };
173
+ /**
174
+ * Refresh the terminal session.
175
+ *
176
+ * #### Notes
177
+ * Failure to reconnect to the session should be caught appropriately
178
+ */
179
+ _this.refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
180
+ var _this$connection2;
181
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
182
+ while (1) switch (_context2.prev = _context2.next) {
183
+ case 0:
184
+ if (!(!_this.isDisposed && _this._isReady)) {
185
+ _context2.next = 4;
186
+ break;
187
+ }
188
+ _context2.next = 3;
189
+ return (_this$connection2 = _this.connection) === null || _this$connection2 === void 0 ? void 0 : _this$connection2.reconnect();
190
+ case 3:
191
+ _this.term.clear();
192
+ case 4:
193
+ case "end":
194
+ return _context2.stop();
195
+ }
196
+ }, _callee2);
197
+ }));
149
198
  _this.resizeTerminal = function () {
150
- var geo = _this.fitAddon.proposeDimensions();
151
- var cols = geo.cols;
152
- var rows = geo.rows - 1; // subtract one row for margin
153
- _this.term.resize(cols, rows);
199
+ _this.fitAddon.fit();
154
200
  };
155
201
  _this.onViewResize = function () {
156
- if (!_this.isVisible || !_this.isAttached) {
202
+ // todo 这里为什么没有触发isAttached
203
+ // if (!this.isVisible || !this.isAttached) {
204
+ // return;
205
+ // }
206
+
207
+ if (!_this.isVisible) {
157
208
  return;
158
209
  }
210
+ _this.processResize();
211
+ };
212
+ _this.processResize = function () {
159
213
  _this.open();
160
214
  _this.resizeTerminal();
215
+ _this.setSessionSize();
161
216
  };
162
217
  _this.open = function () {
163
- var _this$container;
164
- if (_this.termOpened) {
165
- return;
166
- }
167
- var node = (_this$container = _this.container) === null || _this$container === void 0 ? void 0 : _this$container.current;
168
- if (node) {
169
- _this.term.open(node);
170
- }
171
- if (_this.initialData) {
172
- _this.term.write(_this.initialData);
173
- }
174
- _this.termOpened = true;
175
- _this.initialData = '';
176
- if (isFirefox) {
177
- // The software scrollbars don't work with xterm.js, so we disable the scrollbar if we are on firefox.
178
- if (_this.term.element) {
179
- var _this$term$element;
180
- ((_this$term$element = _this.term.element) === null || _this$term$element === void 0 ? void 0 : _this$term$element.children.item(0)).style.overflow = 'hidden';
218
+ try {
219
+ var _this$container;
220
+ if (_this.termOpened) {
221
+ return;
222
+ }
223
+ var node = (_this$container = _this.container) === null || _this$container === void 0 ? void 0 : _this$container.current;
224
+ if (node) {
225
+ _this.term.open(node);
181
226
  }
227
+ if (_this.initialData) {
228
+ _this.term.write(_this.initialData);
229
+ }
230
+ _this.termOpened = true;
231
+ _this.onDidOpenEmitter.fire(true);
232
+ _this.initialData = '';
233
+ if (isFirefox) {
234
+ // The software scrollbars don't work with xterm.js, so we disable the scrollbar if we are on firefox.
235
+ if (_this.term.element) {
236
+ var _this$term$element;
237
+ ((_this$term$element = _this.term.element) === null || _this$term$element === void 0 ? void 0 : _this$term$element.children.item(0)).style.overflow = 'hidden';
238
+ }
239
+ }
240
+ } catch (e) {
241
+ _this.onDidOpenFailureEmitter.fire(e);
242
+ throw e;
182
243
  }
183
244
  };
245
+ _this.onDidOpenFailure = _this.onDidOpenFailureEmitter.event;
246
+ _this.onSizeChanged = _this.onSizeChangedEmitter.event;
247
+ _this.onData = _this.onDataEmitter.event;
248
+ _this.onKey = _this.onKeyEmitter.event;
249
+ _this.onDidClose = _this.onDidCloseEmitter.event;
250
+ _this.onTitleChange = _this.onTitleChangeEmitter.event;
251
+ _this.onReady = _this.onReadyEmitter.event;
184
252
  _this.scrollLineUp = function () {
185
253
  _this.term.scrollLines(-1);
186
254
  };
@@ -202,86 +270,210 @@ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal
202
270
  _this.resetTerminal = function () {
203
271
  _this.term.reset();
204
272
  };
205
- _this.writeLine = function (text) {
206
- _this.term.writeln(text);
273
+ _this.writeLine = function (data) {
274
+ _this.term.writeln(data);
207
275
  };
208
- _this.options = options;
276
+ _this.write = function (data) {
277
+ _this.term.write(data);
278
+ };
279
+ _this.options = _options;
209
280
  _this.title.icon = CodeOutlined;
281
+ _this.config = config;
282
+ _this.themeService = themeService;
283
+ _this.terminalManager = terminalManager;
210
284
  _this.createTerm();
211
- _this.createConnection();
285
+ // 设置自定义事件
286
+ _this.term.attachCustomKeyEventHandler(function (e) {
287
+ return _this.customKeyHandler(e);
288
+ });
289
+
290
+ // 输入
291
+ _this.onData(function (data) {
292
+ if (_this.isDisposed) {
293
+ return;
294
+ }
295
+ if (_this.connection) {
296
+ _this.connection.send({
297
+ type: 'stdin',
298
+ content: [data]
299
+ });
300
+ }
301
+ });
302
+
303
+ // dispose tern
212
304
  if (_this.options.destroyOnClose === true) {
213
305
  _this.toDispose.push(Disposable.create(function () {
214
- return _this.term.dispose();
306
+ _this.term.dispose();
215
307
  }));
216
308
  }
309
+
310
+ // 主题
217
311
  _this.toDispose.push(_this.themeService.onDidChange(function () {
218
- return _this.term.setOption('theme', _this.themeService.theme);
312
+ return _this.term.options.theme = _this.themeService.getTheme();
219
313
  }));
314
+
315
+ // server title
220
316
  _this.toDispose.push(_this.term.onTitleChange(function (title) {
221
317
  if (_this.options.useServerTitle) {
222
318
  _this.title.label = title;
319
+ _this.onTitleChangeEmitter.fire(title);
223
320
  }
224
321
  }));
322
+
323
+ // dispose Emitter
225
324
  _this.toDispose.push(_this.onDidCloseEmitter);
226
325
  _this.toDispose.push(_this.onDidOpenEmitter);
227
326
  _this.toDispose.push(_this.onDidOpenFailureEmitter);
228
327
  _this.toDispose.push(_this.onSizeChangedEmitter);
229
328
  _this.toDispose.push(_this.onDataEmitter);
230
329
  _this.toDispose.push(_this.onKeyEmitter);
330
+
331
+ // bind onSizeChanged
231
332
  _this.toDispose.push(_this.term.onResize(function (data) {
232
333
  _this.onSizeChangedEmitter.fire(data);
233
334
  }));
335
+
336
+ // bind ondata
234
337
  _this.toDispose.push(_this.term.onData(function (data) {
235
338
  _this.onDataEmitter.fire(data);
236
339
  }));
237
- _this.toDispose.push(_this.term.onBinary(function (data) {
238
- _this.onDataEmitter.fire(data);
239
- }));
340
+ _this.toDispose.push(function () {
341
+ // xterm 的 SGR(Select Graphic Rendition)鼠标模式(SGR Mouse Mode),对于特定类型的鼠标事件,xterm 将会发送相应的二进制数据到终端
342
+ /**
343
+ * Adds an event listener for when a binary event fires. This is used to
344
+ * enable non UTF-8 conformant binary messages to be sent to the backend.
345
+ * Currently this is only used for a certain type of mouse reports that
346
+ * happen to be not UTF-8 compatible.
347
+ * The event value is a JS string, pass it to the underlying pty as
348
+ * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
349
+ * @returns an `IDisposable` to stop listening.
350
+ */
351
+ return _this.term.onBinary(function (data) {
352
+ _this.onDataEmitter.fire(data);
353
+ });
354
+ }());
355
+
356
+ // bind onKey
240
357
  _this.toDispose.push(_this.term.onKey(function (data) {
241
358
  _this.onKeyEmitter.fire(data);
242
359
  }));
243
360
  return _this;
244
361
  }
245
- LibroTerminalView = inject(TerminalViewOption)(LibroTerminalView, undefined, 0) || LibroTerminalView;
362
+ LibroTerminalView = inject(TerminalManager)(LibroTerminalView, undefined, 3) || LibroTerminalView;
363
+ LibroTerminalView = inject(TerminalThemeService)(LibroTerminalView, undefined, 2) || LibroTerminalView;
364
+ LibroTerminalView = inject(TerminalConfiguration)(LibroTerminalView, undefined, 1) || LibroTerminalView;
365
+ LibroTerminalView = inject(ViewOption)(LibroTerminalView, undefined, 0) || LibroTerminalView;
246
366
  _createClass(LibroTerminalView, [{
247
- key: "onMessage",
248
- value:
249
- /**
250
- * Handle a message from the terminal session.
251
- */
252
- function onMessage(msg) {
253
- switch (msg.type) {
254
- case 'stdout':
255
- if (msg.content) {
256
- this.term.write(msg.content[0]);
367
+ key: "afterRestore",
368
+ value: function afterRestore() {
369
+ var _this2 = this;
370
+ this.initConnection().then(function (connection) {
371
+ _this2._isReady = true;
372
+ _this2.connection = connection;
373
+ _this2.onReadyEmitter.fire(true);
374
+ _this2.toDispose.push(connection.messageReceived(_this2.onMessage));
375
+ _this2.toDispose.push(connection);
376
+ var dispose = connection.connectionStatusChanged(function () {
377
+ _this2.initOnceAfterConnected(dispose);
378
+ });
379
+ return connection;
380
+ }).catch(function (e) {
381
+ console.error(e);
382
+ });
383
+ }
384
+ }, {
385
+ key: "initConnection",
386
+ value: function () {
387
+ var _initConnection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
388
+ var connection, options, restoreConnection;
389
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
390
+ while (1) switch (_context3.prev = _context3.next) {
391
+ case 0:
392
+ if (this.restoreObj) {
393
+ _context3.next = 7;
394
+ break;
395
+ }
396
+ _context3.next = 3;
397
+ return this.createConnection();
398
+ case 3:
399
+ connection = _context3.sent;
400
+ return _context3.abrupt("return", connection);
401
+ case 7:
402
+ options = _objectSpread(_objectSpread({}, this.options), this.restoreObj);
403
+ _context3.next = 10;
404
+ return this.terminalManager.getOrCreate(options);
405
+ case 10:
406
+ restoreConnection = _context3.sent;
407
+ return _context3.abrupt("return", restoreConnection);
408
+ case 12:
409
+ case "end":
410
+ return _context3.stop();
257
411
  }
258
- break;
259
- case 'disconnect':
260
- this.term.write('\r\n\r\n[Finished… Term Session]\r\n');
261
- break;
262
- default:
263
- break;
412
+ }, _callee3, this);
413
+ }));
414
+ function initConnection() {
415
+ return _initConnection.apply(this, arguments);
264
416
  }
417
+ return initConnection;
418
+ }()
419
+ }, {
420
+ key: "storeState",
421
+ value: function storeState() {
422
+ return {
423
+ name: this.name
424
+ };
425
+ }
426
+ }, {
427
+ key: "restoreState",
428
+ value: function restoreState(oldState) {
429
+ var state = oldState;
430
+ this.restoreObj = state;
431
+ }
432
+
433
+ // todo merge options to initcommand
434
+ }, {
435
+ key: "dispose",
436
+ value: function dispose() {
437
+ var _this$connection3;
438
+ if (!((_this$connection3 = this.connection) !== null && _this$connection3 !== void 0 && _this$connection3.disposed)) {
439
+ var _this$connection4;
440
+ (_this$connection4 = this.connection) === null || _this$connection4 === void 0 || _this$connection4.shutdown().catch(function (reason) {
441
+ console.error("Terminal not shut down: ".concat(reason));
442
+ });
443
+ }
444
+ _get(_getPrototypeOf(LibroTerminalView.prototype), "dispose", this).call(this);
265
445
  }
266
446
  }, {
267
- key: "initialConnection",
268
- value: function initialConnection() {
269
- var _this$connection;
447
+ key: "initOnceAfterConnected",
448
+ value: function initOnceAfterConnected(dispose) {
449
+ var _this$connection5;
270
450
  if (this.isDisposed) {
271
451
  return;
272
452
  }
273
- if (((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.connectionStatus) !== 'connected') {
453
+ if (((_this$connection5 = this.connection) === null || _this$connection5 === void 0 ? void 0 : _this$connection5.connectionStatus) !== 'connected') {
274
454
  return;
275
455
  }
276
- this.title.label = "Terminal ".concat(this.connection.name);
277
- if (this.connection && this.options.initialCommand) {
278
- var _this$connection2;
279
- (_this$connection2 = this.connection) === null || _this$connection2 === void 0 || _this$connection2.send({
280
- type: 'stdin',
281
- content: [this.options.initialCommand + '\r']
282
- });
456
+ this.initialTitle();
457
+ this.setSessionSize();
458
+ this.initialCommand();
459
+ // 只执行一次
460
+ if (dispose) {
461
+ dispose.dispose();
283
462
  }
284
463
  }
464
+ }, {
465
+ key: "initialTitle",
466
+ value:
467
+ // default title
468
+ function initialTitle() {
469
+ var _this$connection6;
470
+ if (((_this$connection6 = this.connection) === null || _this$connection6 === void 0 ? void 0 : _this$connection6.connectionStatus) !== 'connected') {
471
+ return;
472
+ }
473
+ var title = "Terminal ".concat(this.connection.name);
474
+ this.title.label = title;
475
+ this.onTitleChangeEmitter.fire(title);
476
+ }
285
477
  }, {
286
478
  key: "enableCopy",
287
479
  get: function get() {
@@ -297,21 +489,126 @@ export var LibroTerminalView = (_dec = transient(), _dec2 = view('libro-terminal
297
489
  get: function get() {
298
490
  return this.config.get('terminal.integrated.copyOnSelection');
299
491
  }
492
+ }, {
493
+ key: "onViewMount",
494
+ value: function onViewMount() {
495
+ this.open();
496
+ }
497
+ }, {
498
+ key: "onViewUnmount",
499
+ value: function onViewUnmount() {
500
+ this.termOpened = false;
501
+ }
502
+ }, {
503
+ key: "setSessionSize",
504
+ value:
505
+ /**
506
+ * Set the size of the terminal in the session.
507
+ */
508
+ function setSessionSize() {
509
+ if (this.container && this.container.current) {
510
+ var content = [this.term.rows, this.term.cols, this.container.current.offsetHeight, this.container.current.offsetWidth];
511
+ if (!this.isDisposed && this.connection) {
512
+ this.connection.send({
513
+ type: 'set_size',
514
+ content: content
515
+ });
516
+ }
517
+ }
518
+ }
519
+ }, {
520
+ key: "hasWebGLContext",
521
+ value: function hasWebGLContext() {
522
+ // Create canvas element. The canvas is not added to the
523
+ // document itself, so it is never displayed in the
524
+ // browser window.
525
+ var canvas = document.createElement('canvas');
526
+
527
+ // Get WebGLRenderingContext from canvas element.
528
+ var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
529
+
530
+ // Report the result.
531
+ try {
532
+ return gl instanceof WebGLRenderingContext;
533
+ } catch (error) {
534
+ return false;
535
+ }
536
+ }
537
+
538
+ /**
539
+ * Create a xterm.js terminal
540
+ */
541
+ }, {
542
+ key: "createTerminal",
543
+ value: function createTerminal(options) {
544
+ var term = new Terminal(options);
545
+ this.addRenderer(term);
546
+ var fitAddon = new FitAddon();
547
+ term.loadAddon(fitAddon);
548
+ term.loadAddon(new WebLinksAddon());
549
+ return [term, fitAddon];
550
+ }
551
+ }, {
552
+ key: "addRenderer",
553
+ value: function addRenderer(term) {
554
+ var _this3 = this;
555
+ var supportWebGL = this.hasWebGLContext();
556
+ var renderer = this.hasWebGLContext() ? new WebglAddon() : new CanvasAddon();
557
+ term.loadAddon(renderer);
558
+ if (supportWebGL) {
559
+ renderer.onContextLoss(function (event) {
560
+ // console.debug('WebGL context lost - reinitialize Xtermjs renderer.');
561
+ renderer.dispose();
562
+ // If the Webgl context is lost, reinitialize the addon
563
+ _this3.addRenderer(term);
564
+ });
565
+ }
566
+ }
567
+ }, {
568
+ key: "name",
569
+ get:
570
+ /**
571
+ * Terminal is ready event
572
+ */
573
+ function get() {
574
+ var _this$connection7;
575
+ return ((_this$connection7 = this.connection) === null || _this$connection7 === void 0 ? void 0 : _this$connection7.name) || '';
576
+ }
577
+ }, {
578
+ key: "hasSelection",
579
+ value:
580
+ /**
581
+ * Check if terminal has any text selected.
582
+ */
583
+ function hasSelection() {
584
+ if (!this.isDisposed && this._isReady) {
585
+ return this.term.hasSelection();
586
+ }
587
+ return false;
588
+ }
589
+
590
+ /**
591
+ * Paste text into terminal.
592
+ */
593
+ }, {
594
+ key: "paste",
595
+ value: function paste(data) {
596
+ if (!this.isDisposed && this._isReady) {
597
+ return this.term.paste(data);
598
+ }
599
+ }
600
+
601
+ /**
602
+ * Get selected text from terminal.
603
+ */
604
+ }, {
605
+ key: "getSelection",
606
+ value: function getSelection() {
607
+ if (!this.isDisposed && this._isReady) {
608
+ return this.term.getSelection();
609
+ }
610
+ return null;
611
+ }
300
612
  }]);
301
613
  return LibroTerminalView;
302
- }(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "config", [_dec3], {
303
- configurable: true,
304
- enumerable: true,
305
- writable: true,
306
- initializer: null
307
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "themeService", [_dec4], {
308
- configurable: true,
309
- enumerable: true,
310
- writable: true,
311
- initializer: null
312
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "terminalManager", [_dec5], {
313
- configurable: true,
314
- enumerable: true,
315
- writable: true,
316
- initializer: null
317
- })), _class2)) || _class) || _class);
614
+ }(BaseStatefulView)) || _class) || _class);