@difizen/libro-terminal 0.1.0

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 ADDED
@@ -0,0 +1,317 @@
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;
3
+ 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
+ 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
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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
+ 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
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ 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); }
12
+ 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
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ 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); }; }
15
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ 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
+ 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
+ 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';
24
+ import { forwardRef } from 'react';
25
+ import { Terminal } from 'xterm';
26
+ import { FitAddon } from 'xterm-addon-fit';
27
+ import { DEFAULT_TERMINAL_RENDERER_TYPE, isTerminalRendererType } from "./configuration.js";
28
+ import { TerminalConfiguration } from "./configuration.js";
29
+ import { TerminalManager } from "./manager.js";
30
+ import { TerminalViewOption } from "./protocol.js";
31
+ import { TerminalThemeService } from "./theme-service.js";
32
+ import { jsx as _jsx } from "react/jsx-runtime";
33
+ export var TerminalComponent = /*#__PURE__*/forwardRef(function TerminalComponent(_props, ref) {
34
+ // const instance = useInject<LibroTerminalView>(ViewInstance);
35
+ return /*#__PURE__*/_jsx("div", {
36
+ tabIndex: 1,
37
+ className: "libro-terminal",
38
+ ref: ref,
39
+ children: "/"
40
+ });
41
+ });
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);
44
+ var _super = _createSuper(LibroTerminalView);
45
+ function LibroTerminalView(options) {
46
+ var _this;
47
+ _classCallCheck(this, LibroTerminalView);
48
+ _this = _super.call(this);
49
+ _this.view = TerminalComponent;
50
+ _this.termOpened = false;
51
+ _this.initialData = '';
52
+ _initializerDefineProperty(_this, "config", _descriptor, _assertThisInitialized(_this));
53
+ _initializerDefineProperty(_this, "themeService", _descriptor2, _assertThisInitialized(_this));
54
+ _initializerDefineProperty(_this, "terminalManager", _descriptor3, _assertThisInitialized(_this));
55
+ _this.toDisposeOnConnect = new DisposableCollection();
56
+ _this.onDidOpenEmitter = new Emitter();
57
+ _this.onDidOpen = _this.onDidOpenEmitter.event;
58
+ _this.onDidOpenFailureEmitter = new Emitter();
59
+ _this.onDidOpenFailure = _this.onDidOpenFailureEmitter.event;
60
+ _this.onSizeChangedEmitter = new Emitter();
61
+ _this.onSizeChanged = _this.onSizeChangedEmitter.event;
62
+ _this.onDataEmitter = new Emitter();
63
+ _this.onData = _this.onDataEmitter.event;
64
+ _this.onKeyEmitter = new Emitter();
65
+ _this.onKey = _this.onKeyEmitter.event;
66
+ _this.onDidCloseEmitter = new Emitter();
67
+ _this.onDidClose = _this.onDidCloseEmitter.event;
68
+ _this.createConnection = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
69
+ var connection;
70
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71
+ while (1) switch (_context.prev = _context.next) {
72
+ case 0:
73
+ _context.next = 2;
74
+ return _this.terminalManager.getOrCreate(_this.options);
75
+ case 2:
76
+ 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:
88
+ case "end":
89
+ return _context.stop();
90
+ }
91
+ }, _callee);
92
+ }));
93
+ _this.createTerm = function () {
94
+ var term = new Terminal({
95
+ cursorBlink: _this.config.get('terminal.integrated.cursorBlinking'),
96
+ cursorStyle: _this.getCursorStyle(),
97
+ cursorWidth: _this.config.get('terminal.integrated.cursorWidth'),
98
+ fontFamily: _this.config.get('terminal.integrated.fontFamily'),
99
+ fontSize: _this.config.get('terminal.integrated.fontSize'),
100
+ fontWeight: _this.config.get('terminal.integrated.fontWeight'),
101
+ fontWeightBold: _this.config.get('terminal.integrated.fontWeightBold'),
102
+ drawBoldTextInBrightColors: _this.config.get('terminal.integrated.drawBoldTextInBrightColors'),
103
+ letterSpacing: _this.config.get('terminal.integrated.letterSpacing'),
104
+ lineHeight: _this.config.get('terminal.integrated.lineHeight'),
105
+ scrollback: _this.config.get('terminal.integrated.scrollback'),
106
+ fastScrollSensitivity: _this.config.get('terminal.integrated.fastScrollSensitivity'),
107
+ rendererType: _this.getTerminalRendererType(_this.config.get('terminal.integrated.rendererType')),
108
+ theme: _this.themeService.theme
109
+ });
110
+ var fitAddon = new FitAddon();
111
+ term.loadAddon(fitAddon);
112
+ _this.fitAddon = fitAddon;
113
+ _this.term = term;
114
+ _this.term.attachCustomKeyEventHandler(function (e) {
115
+ return _this.customKeyHandler(e);
116
+ });
117
+ };
118
+ _this.customKeyHandler = function (event) {
119
+ var keyBindings = KeyCode.createKeyCode(event).toString();
120
+ var ctrlCmdCopy = isOSX && keyBindings === 'meta+c' || !isOSX && keyBindings === 'ctrl+c';
121
+ var ctrlCmdPaste = isOSX && keyBindings === 'meta+v' || !isOSX && keyBindings === 'ctrl+v';
122
+ if (ctrlCmdCopy && _this.enableCopy && _this.term.hasSelection()) {
123
+ return false;
124
+ }
125
+ if (ctrlCmdPaste && _this.enablePaste) {
126
+ return false;
127
+ }
128
+ return true;
129
+ };
130
+ /**
131
+ * Get the cursor style compatible with `xterm`.
132
+ * @returns CursorStyle
133
+ */
134
+ _this.getCursorStyle = function () {
135
+ var value = _this.config.get('terminal.integrated.cursorStyle');
136
+ return value === 'line' ? 'bar' : value;
137
+ };
138
+ /**
139
+ * Returns given renderer type if it is valid and supported or default renderer otherwise.
140
+ *
141
+ * @param terminalRendererType desired terminal renderer type
142
+ */
143
+ _this.getTerminalRendererType = function (terminalRendererType) {
144
+ if (terminalRendererType && isTerminalRendererType(terminalRendererType)) {
145
+ return terminalRendererType;
146
+ }
147
+ return DEFAULT_TERMINAL_RENDERER_TYPE;
148
+ };
149
+ _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);
154
+ };
155
+ _this.onViewResize = function () {
156
+ if (!_this.isVisible || !_this.isAttached) {
157
+ return;
158
+ }
159
+ _this.open();
160
+ _this.resizeTerminal();
161
+ };
162
+ _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';
181
+ }
182
+ }
183
+ };
184
+ _this.scrollLineUp = function () {
185
+ _this.term.scrollLines(-1);
186
+ };
187
+ _this.scrollLineDown = function () {
188
+ _this.term.scrollLines(1);
189
+ };
190
+ _this.scrollToTop = function () {
191
+ _this.term.scrollToTop();
192
+ };
193
+ _this.scrollToBottom = function () {
194
+ _this.term.scrollToBottom();
195
+ };
196
+ _this.scrollPageUp = function () {
197
+ _this.term.scrollPages(-1);
198
+ };
199
+ _this.scrollPageDown = function () {
200
+ _this.term.scrollPages(1);
201
+ };
202
+ _this.resetTerminal = function () {
203
+ _this.term.reset();
204
+ };
205
+ _this.writeLine = function (text) {
206
+ _this.term.writeln(text);
207
+ };
208
+ _this.options = options;
209
+ _this.title.icon = CodeOutlined;
210
+ _this.createTerm();
211
+ _this.createConnection();
212
+ if (_this.options.destroyOnClose === true) {
213
+ _this.toDispose.push(Disposable.create(function () {
214
+ return _this.term.dispose();
215
+ }));
216
+ }
217
+ _this.toDispose.push(_this.themeService.onDidChange(function () {
218
+ return _this.term.setOption('theme', _this.themeService.theme);
219
+ }));
220
+ _this.toDispose.push(_this.term.onTitleChange(function (title) {
221
+ if (_this.options.useServerTitle) {
222
+ _this.title.label = title;
223
+ }
224
+ }));
225
+ _this.toDispose.push(_this.onDidCloseEmitter);
226
+ _this.toDispose.push(_this.onDidOpenEmitter);
227
+ _this.toDispose.push(_this.onDidOpenFailureEmitter);
228
+ _this.toDispose.push(_this.onSizeChangedEmitter);
229
+ _this.toDispose.push(_this.onDataEmitter);
230
+ _this.toDispose.push(_this.onKeyEmitter);
231
+ _this.toDispose.push(_this.term.onResize(function (data) {
232
+ _this.onSizeChangedEmitter.fire(data);
233
+ }));
234
+ _this.toDispose.push(_this.term.onData(function (data) {
235
+ _this.onDataEmitter.fire(data);
236
+ }));
237
+ _this.toDispose.push(_this.term.onBinary(function (data) {
238
+ _this.onDataEmitter.fire(data);
239
+ }));
240
+ _this.toDispose.push(_this.term.onKey(function (data) {
241
+ _this.onKeyEmitter.fire(data);
242
+ }));
243
+ return _this;
244
+ }
245
+ LibroTerminalView = inject(TerminalViewOption)(LibroTerminalView, undefined, 0) || LibroTerminalView;
246
+ _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]);
257
+ }
258
+ break;
259
+ case 'disconnect':
260
+ this.term.write('\r\n\r\n[Finished… Term Session]\r\n');
261
+ break;
262
+ default:
263
+ break;
264
+ }
265
+ }
266
+ }, {
267
+ key: "initialConnection",
268
+ value: function initialConnection() {
269
+ var _this$connection;
270
+ if (this.isDisposed) {
271
+ return;
272
+ }
273
+ if (((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.connectionStatus) !== 'connected') {
274
+ return;
275
+ }
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
+ });
283
+ }
284
+ }
285
+ }, {
286
+ key: "enableCopy",
287
+ get: function get() {
288
+ return this.config.get('terminal.enableCopy');
289
+ }
290
+ }, {
291
+ key: "enablePaste",
292
+ get: function get() {
293
+ return this.config.get('terminal.enablePaste');
294
+ }
295
+ }, {
296
+ key: "copyOnSelection",
297
+ get: function get() {
298
+ return this.config.get('terminal.integrated.copyOnSelection');
299
+ }
300
+ }]);
301
+ 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);
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@difizen/libro-terminal",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro"
7
+ ],
8
+ "repository": "git@github.com:difizen/libro.git",
9
+ "license": "MIT",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "typings": "./es/index.d.ts",
14
+ "default": "./es/index.js"
15
+ },
16
+ "./mock": {
17
+ "typings": "./es/mock/index.d.ts",
18
+ "default": "./es/mock/index.js"
19
+ },
20
+ "./es/mock": {
21
+ "typings": "./es/mock/index.d.ts",
22
+ "default": "./es/mock/index.js"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "main": "es/index.js",
27
+ "module": "es/index.js",
28
+ "typings": "es/index.d.ts",
29
+ "files": [
30
+ "es",
31
+ "src"
32
+ ],
33
+ "dependencies": {
34
+ "@difizen/libro-core": "^0.1.0",
35
+ "@difizen/libro-common": "^0.1.0",
36
+ "@difizen/libro-kernel": "^0.1.0",
37
+ "@difizen/mana-app": "latest",
38
+ "@ant-design/icons": "^5.1.0",
39
+ "xterm": "^4.16.0",
40
+ "xterm-addon-fit": "^0.5.0",
41
+ "xterm-addon-search": "^0.8.2"
42
+ },
43
+ "peerDependencies": {
44
+ "antd": "^5.8.6",
45
+ "react": "^18.2.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/react": "^18.2.25"
49
+ },
50
+ "scripts": {
51
+ "setup": "father build",
52
+ "build": "father build",
53
+ "test": ": Note: lint task is delegated to test:* scripts",
54
+ "test:vitest": "vitest run",
55
+ "test:jest": "jest",
56
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
57
+ "coverage:vitest": "vitest run --coverage",
58
+ "coverage:jest": "jest --coverage",
59
+ "lint": ": Note: lint task is delegated to lint:* scripts",
60
+ "lint:eslint": "eslint src",
61
+ "lint:tsc": "tsc --noEmit"
62
+ }
63
+ }
@@ -0,0 +1,276 @@
1
+ import type { ConfigurationNode } from '@difizen/mana-app';
2
+ import { isOSX, isWindows, singleton } from '@difizen/mana-app';
3
+
4
+ export type TerminalRendererType = 'canvas' | 'dom';
5
+ export const DEFAULT_TERMINAL_RENDERER_TYPE = 'canvas';
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ export function isTerminalRendererType(arg: any): arg is TerminalRendererType {
8
+ return typeof arg === 'string' && (arg === 'canvas' || arg === 'dom');
9
+ }
10
+
11
+ export type CursorStyle = 'block' | 'underline' | 'bar';
12
+
13
+ export const terminalEnableCopy: ConfigurationNode<any> = {
14
+ id: 'terminal.enableCopy',
15
+ schema: {
16
+ type: 'boolean',
17
+ },
18
+
19
+ description: 'Enable ctrl-c (cmd-c on macOS) to copy selected text',
20
+ defaultValue: true,
21
+ };
22
+ export const terminalEnablePaste: ConfigurationNode<any> = {
23
+ id: 'terminal.enablePaste',
24
+ schema: {
25
+ type: 'boolean',
26
+ },
27
+
28
+ description: 'Enable ctrl-v (cmd-v on macOS) to paste from clipboard',
29
+ defaultValue: true,
30
+ };
31
+ export const terminalIntegratedFontFamily: ConfigurationNode<any> = {
32
+ id: 'terminal.integrated.fontFamily',
33
+ schema: {
34
+ type: 'string',
35
+ },
36
+
37
+ description:
38
+ "Controls the font family of the terminal, this defaults to `#editor.fontFamily#`'s value.",
39
+ defaultValue: isOSX
40
+ ? "Menlo, Monaco, 'Courier New', monospace"
41
+ : isWindows
42
+ ? "Consolas, 'Courier New', monospace"
43
+ : "'Droid Sans Mono', 'monospace', monospace",
44
+ };
45
+ export const terminalIntegratedFontSize: ConfigurationNode<any> = {
46
+ id: 'terminal.integrated.fontSize',
47
+ schema: {
48
+ type: 'number',
49
+ minimum: 6,
50
+ },
51
+
52
+ description: 'Controls the font size in pixels of the terminal.',
53
+ defaultValue: 12,
54
+ };
55
+ export const terminalIntegratedFontWeight: ConfigurationNode<any> = {
56
+ id: 'terminal.integrated.fontWeight',
57
+ schema: {
58
+ type: 'string',
59
+ },
60
+
61
+ // enum: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
62
+ description:
63
+ 'The font weight to use within the terminal for non-bold text. Accepts "normal" and "bold" keywords or numbers between 1 and 1000.',
64
+ defaultValue: 'normal',
65
+ };
66
+ export const terminalIntegratedFontWeightBold: ConfigurationNode<any> = {
67
+ id: 'terminal.integrated.fontWeightBold',
68
+ schema: {
69
+ type: 'string',
70
+ },
71
+
72
+ // enum: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
73
+ description:
74
+ 'The font weight to use within the terminal for bold text. Accepts "normal" and "bold" keywords or numbers between 1 and 1000.',
75
+ defaultValue: 'bold',
76
+ };
77
+ export const terminalIntegratedDrawBoldTextInBrightColors: ConfigurationNode<any> = {
78
+ id: 'terminal.integrated.drawBoldTextInBrightColors',
79
+ description:
80
+ 'Controls whether bold text in the terminal will always use the "bright" ANSI color variant.',
81
+ schema: {
82
+ type: 'boolean',
83
+ },
84
+
85
+ defaultValue: true,
86
+ };
87
+ export const terminalIntegratedLetterSpacing: ConfigurationNode<any> = {
88
+ id: 'terminal.integrated.letterSpacing',
89
+ description:
90
+ 'Controls the letter spacing of the terminal, this is an integer value which represents the amount of additional pixels to add between characters.',
91
+ schema: {
92
+ type: 'number',
93
+ },
94
+
95
+ defaultValue: 1,
96
+ };
97
+ export const terminalIntegratedLineHeight: ConfigurationNode<any> = {
98
+ id: 'terminal.integrated.lineHeight',
99
+ description:
100
+ 'Controls the line height of the terminal, this number is multiplied by the terminal font size to get the actual line-height in pixels.',
101
+ schema: {
102
+ type: 'number',
103
+ minimum: 1,
104
+ },
105
+
106
+ defaultValue: 1,
107
+ };
108
+ export const terminalIntegratedScrollback: ConfigurationNode<any> = {
109
+ id: 'terminal.integrated.scrollback',
110
+ description: 'Controls the maximum amount of lines the terminal keeps in its buffer.',
111
+ schema: {
112
+ type: 'number',
113
+ },
114
+
115
+ defaultValue: 1000,
116
+ };
117
+ export const terminalIntegratedFastScrollSensitivity: ConfigurationNode<any> = {
118
+ id: 'terminal.integrated.fastScrollSensitivity',
119
+ description: 'Scrolling speed multiplier when pressing `Alt`.',
120
+ schema: {
121
+ type: 'number',
122
+ },
123
+
124
+ defaultValue: 5,
125
+ };
126
+ export const terminalIntegratedRendererType: ConfigurationNode<any> = {
127
+ id: 'terminal.integrated.rendererType',
128
+ description: 'Controls how the terminal is rendered.',
129
+ schema: {
130
+ type: 'string',
131
+ },
132
+
133
+ // enum: ['canvas', 'dom'],
134
+ defaultValue: 'canvas',
135
+ };
136
+ export const terminalIntegratedCopyOnSelection: ConfigurationNode<any> = {
137
+ id: 'terminal.integrated.copyOnSelection',
138
+ description:
139
+ 'Controls whether text selected in the terminal will be copied to the clipboard.',
140
+ schema: {
141
+ type: 'boolean',
142
+ },
143
+
144
+ defaultValue: false,
145
+ };
146
+ export const terminalIntegratedCursorBlinking: ConfigurationNode<any> = {
147
+ id: 'terminal.integrated.cursorBlinking',
148
+ description: 'Controls whether the terminal cursor blinks.',
149
+ schema: {
150
+ type: 'boolean',
151
+ },
152
+
153
+ defaultValue: false,
154
+ };
155
+ export const terminalIntegratedCursorStyle: ConfigurationNode<any> = {
156
+ id: 'terminal.integrated.cursorStyle',
157
+ description: 'Controls the style of terminal cursor.',
158
+ // enum: ['block', 'underline', 'line'],
159
+ defaultValue: 'block',
160
+ schema: {
161
+ type: 'string',
162
+ },
163
+ };
164
+ export const terminalIntegratedCursorWidth: ConfigurationNode<any> = {
165
+ id: 'terminal.integrated.cursorWidth',
166
+ description:
167
+ 'Controls the width of the cursor when `#terminal.integrated.cursorStyle#` is set to `line`.',
168
+ schema: {
169
+ type: 'number',
170
+ },
171
+
172
+ defaultValue: 1,
173
+ };
174
+ export const terminalIntegratedShellWindows: ConfigurationNode<any> = {
175
+ id: 'terminal.integrated.shell.windows',
176
+ schema: {
177
+ type: 'string',
178
+ },
179
+ // typeDetails: { isFilepath: true },
180
+ description:
181
+ "The path of the shell that the terminal uses on Windows. (defaultValue: '{0}').",
182
+ defaultValue: undefined,
183
+ };
184
+ export const terminalIntegratedShellOsx: ConfigurationNode<any> = {
185
+ id: 'terminal.integrated.shell.osx',
186
+ schema: {
187
+ type: 'string',
188
+ },
189
+ description:
190
+ "The path of the shell that the terminal uses on macOS (defaultValue: '{0}'}).",
191
+ defaultValue: undefined,
192
+ };
193
+ export const terminalIntegratedShellLinux: ConfigurationNode<any> = {
194
+ id: 'terminal.integrated.shell.linux',
195
+ schema: {
196
+ type: 'string',
197
+ },
198
+ description:
199
+ "The path of the shell that the terminal uses on Linux (defaultValue: '{0}'}).",
200
+ defaultValue: undefined,
201
+ };
202
+ export const terminalIntegratedShellArgsWindows: ConfigurationNode<any> = {
203
+ id: 'terminal.integrated.shellArgs.windows',
204
+ schema: {
205
+ type: 'string',
206
+ },
207
+
208
+ description: 'The command line arguments to use when on the Windows terminal.',
209
+ defaultValue: [],
210
+ };
211
+ export const terminalIntegratedShellArgsOsx: ConfigurationNode<any> = {
212
+ id: 'terminal.integrated.shellArgs.osx',
213
+ schema: {
214
+ type: 'string',
215
+ },
216
+
217
+ description: 'The command line arguments to use when on the macOS terminal.',
218
+ defaultValue: ['-l'],
219
+ };
220
+ export const terminalIntegratedShellArgsLinux: ConfigurationNode<any> = {
221
+ id: 'terminal.integrated.shellArgs.linux',
222
+ schema: {
223
+ type: 'string',
224
+ },
225
+
226
+ description: 'The command line arguments to use when on the Linux terminal.',
227
+ defaultValue: [],
228
+ };
229
+ export const terminalIntegratedConfirmOnExit: ConfigurationNode<any> = {
230
+ id: 'terminal.integrated.confirmOnExit',
231
+ schema: {
232
+ type: 'string',
233
+ },
234
+ description:
235
+ 'Controls whether to confirm when the window closes if there are active terminal sessions.',
236
+ // enum: ['never', 'always', 'hasChildProcesses'],
237
+ // enumDescriptions: [
238
+ // nls.localize('theia/terminal/confirmCloseNever', 'Never confirm.'),
239
+ // nls.localize('theia/terminal/confirmCloseAlways', 'Always confirm if there are terminals.'),
240
+ // nls.localize('theia/terminal/confirmCloseChildren', 'Confirm if there are any terminals that have child processes.'),
241
+ // ],
242
+ defaultValue: 'never',
243
+ };
244
+
245
+ @singleton()
246
+ export class TerminalConfiguration {
247
+ configs = [
248
+ terminalEnableCopy,
249
+ terminalEnablePaste,
250
+ terminalIntegratedFontFamily,
251
+ terminalIntegratedFontSize,
252
+ terminalIntegratedFontWeight,
253
+ terminalIntegratedFontWeightBold,
254
+ terminalIntegratedDrawBoldTextInBrightColors,
255
+ terminalIntegratedLetterSpacing,
256
+ terminalIntegratedLineHeight,
257
+ terminalIntegratedScrollback,
258
+ terminalIntegratedFastScrollSensitivity,
259
+ terminalIntegratedRendererType,
260
+ terminalIntegratedCopyOnSelection,
261
+ terminalIntegratedCursorBlinking,
262
+ terminalIntegratedCursorStyle,
263
+ terminalIntegratedCursorWidth,
264
+ terminalIntegratedShellWindows,
265
+ terminalIntegratedShellOsx,
266
+ terminalIntegratedShellLinux,
267
+ terminalIntegratedShellArgsWindows,
268
+ terminalIntegratedShellArgsOsx,
269
+ terminalIntegratedShellArgsLinux,
270
+ terminalIntegratedConfirmOnExit,
271
+ ];
272
+
273
+ get(key: string) {
274
+ return this.configs.find((item) => item.id === key)?.defaultValue;
275
+ }
276
+ }