react-terminal-viewer-cicd 2.0.4

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.
Files changed (99) hide show
  1. package/README.md +181 -0
  2. package/dist/esm/Addon/EventEmiter.d.ts +18 -0
  3. package/dist/esm/Addon/EventEmiter.js +64 -0
  4. package/dist/esm/Addon/HighlightAddon.d.ts +26 -0
  5. package/dist/esm/Addon/HighlightAddon.js +188 -0
  6. package/dist/esm/Addon/SearchAddon.d.ts +140 -0
  7. package/dist/esm/Addon/SearchAddon.js +797 -0
  8. package/dist/esm/Addon/WorkerLog/GlobalContext.d.ts +10 -0
  9. package/dist/esm/Addon/WorkerLog/GlobalContext.js +37 -0
  10. package/dist/esm/Addon/WorkerLog/LimitMap.d.ts +14 -0
  11. package/dist/esm/Addon/WorkerLog/LimitMap.js +54 -0
  12. package/dist/esm/Addon/WorkerLog/LogWorker.d.ts +2 -0
  13. package/dist/esm/Addon/WorkerLog/LogWorker.js +13 -0
  14. package/dist/esm/Addon/WorkerLog/Logs.d.ts +21 -0
  15. package/dist/esm/Addon/WorkerLog/Logs.js +60 -0
  16. package/dist/esm/Addon/WorkerLog/Mark.d.ts +36 -0
  17. package/dist/esm/Addon/WorkerLog/Mark.js +155 -0
  18. package/dist/esm/Addon/WorkerLog/Searcher.d.ts +16 -0
  19. package/dist/esm/Addon/WorkerLog/Searcher.js +88 -0
  20. package/dist/esm/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
  21. package/dist/esm/Addon/WorkerLog/WebWokerServer.js +57 -0
  22. package/dist/esm/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
  23. package/dist/esm/Addon/WorkerLog/WebWorkerClient.js +83 -0
  24. package/dist/esm/Addon/WorkerLog/log.worker.d.ts +1 -0
  25. package/dist/esm/Addon/WorkerLog/log.worker.js +63 -0
  26. package/dist/esm/Addon/WorkerLog/types.d.ts +18 -0
  27. package/dist/esm/Addon/WorkerLog/types.js +1 -0
  28. package/dist/esm/Addon/useAddon.d.ts +9 -0
  29. package/dist/esm/Addon/useAddon.js +33 -0
  30. package/dist/esm/Hooks/useBatchProcess.d.ts +2 -0
  31. package/dist/esm/Hooks/useBatchProcess.js +47 -0
  32. package/dist/esm/Hooks/useCache.d.ts +31 -0
  33. package/dist/esm/Hooks/useCache.js +206 -0
  34. package/dist/esm/Hooks/useDebounceInput.d.ts +3 -0
  35. package/dist/esm/Hooks/useDebounceInput.js +26 -0
  36. package/dist/esm/Hooks/useLocalStore.d.ts +2 -0
  37. package/dist/esm/Hooks/useLocalStore.js +9 -0
  38. package/dist/esm/Hooks/useRemote.d.ts +30 -0
  39. package/dist/esm/Hooks/useRemote.js +398 -0
  40. package/dist/esm/Hooks/useThrottle.d.ts +2 -0
  41. package/dist/esm/Hooks/useThrottle.js +13 -0
  42. package/dist/esm/Hooks/useWorkerLogs.d.ts +9 -0
  43. package/dist/esm/Hooks/useWorkerLogs.js +162 -0
  44. package/dist/esm/TerminalViewer/index.d.ts +185 -0
  45. package/dist/esm/TerminalViewer/index.js +292 -0
  46. package/dist/esm/TerminalViewer/index.less +17 -0
  47. package/dist/esm/TerminalViewerBody/index.d.ts +87 -0
  48. package/dist/esm/TerminalViewerBody/index.js +248 -0
  49. package/dist/esm/TerminalViewerBody/index.less +51 -0
  50. package/dist/esm/TerminalViewerHeader/index.d.ts +88 -0
  51. package/dist/esm/TerminalViewerHeader/index.js +129 -0
  52. package/dist/esm/TerminalViewerHeader/index.less +143 -0
  53. package/dist/esm/TerminalViewerToolBar/index.d.ts +46 -0
  54. package/dist/esm/TerminalViewerToolBar/index.js +28 -0
  55. package/dist/esm/TerminalViewerToolBar/index.less +32 -0
  56. package/dist/esm/TerminalViewerVirtualDom/index.d.ts +71 -0
  57. package/dist/esm/TerminalViewerVirtualDom/index.js +309 -0
  58. package/dist/esm/TerminalViewerVirtualDom/index.less +68 -0
  59. package/dist/esm/index.d.ts +9 -0
  60. package/dist/esm/index.js +9 -0
  61. package/dist/esm/mock/index.d.ts +12 -0
  62. package/dist/esm/mock/index.js +98 -0
  63. package/dist/esm/types.d.ts +30 -0
  64. package/dist/esm/types.js +1 -0
  65. package/dist/worker/Addon/EventEmiter.d.ts +18 -0
  66. package/dist/worker/Addon/HighlightAddon.d.ts +26 -0
  67. package/dist/worker/Addon/SearchAddon.d.ts +140 -0
  68. package/dist/worker/Addon/WorkerLog/GlobalContext.d.ts +10 -0
  69. package/dist/worker/Addon/WorkerLog/LimitMap.d.ts +14 -0
  70. package/dist/worker/Addon/WorkerLog/LogWorker.d.ts +2 -0
  71. package/dist/worker/Addon/WorkerLog/Logs.d.ts +21 -0
  72. package/dist/worker/Addon/WorkerLog/Mark.d.ts +36 -0
  73. package/dist/worker/Addon/WorkerLog/Searcher.d.ts +16 -0
  74. package/dist/worker/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
  75. package/dist/worker/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
  76. package/dist/worker/Addon/WorkerLog/log.worker.d.ts +1 -0
  77. package/dist/worker/Addon/WorkerLog/types.d.ts +18 -0
  78. package/dist/worker/Addon/useAddon.d.ts +9 -0
  79. package/dist/worker/Hooks/useBatchProcess.d.ts +2 -0
  80. package/dist/worker/Hooks/useCache.d.ts +31 -0
  81. package/dist/worker/Hooks/useDebounceInput.d.ts +3 -0
  82. package/dist/worker/Hooks/useLocalStore.d.ts +2 -0
  83. package/dist/worker/Hooks/useRemote.d.ts +30 -0
  84. package/dist/worker/Hooks/useRemote.test.d.ts +1 -0
  85. package/dist/worker/Hooks/useThrottle.d.ts +2 -0
  86. package/dist/worker/Hooks/useWorkerLogs.d.ts +9 -0
  87. package/dist/worker/TerminalViewer/index.d.ts +185 -0
  88. package/dist/worker/TerminalViewer/index.test.d.ts +1 -0
  89. package/dist/worker/TerminalViewerBody/index.d.ts +87 -0
  90. package/dist/worker/TerminalViewerBody/index.test.d.ts +1 -0
  91. package/dist/worker/TerminalViewerHeader/index.d.ts +88 -0
  92. package/dist/worker/TerminalViewerToolBar/index.d.ts +46 -0
  93. package/dist/worker/TerminalViewerVirtualDom/index.d.ts +71 -0
  94. package/dist/worker/index.d.ts +9 -0
  95. package/dist/worker/log.worker.js +2 -0
  96. package/dist/worker/log.worker.js.map +1 -0
  97. package/dist/worker/mock/index.d.ts +12 -0
  98. package/dist/worker/types.d.ts +30 -0
  99. package/package.json +97 -0
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ <h1 align="center">
2
+ react-terminal-viewer
3
+ </h1>
4
+
5
+ <p align="center">基于 xterm.js 内核的 React 日志组件</p>
6
+
7
+ <p align="center">
8
+ <a href="https://gitee.com/oschina/react-terminal-viewer/gitee_go/pipelines"><img src="https://img.shields.io/badge/codecov-20%25-green" data-canonical-src="https://img.shields.io/badge/codecov-20%25-green"/></a>
9
+ <a href="https://www.npmjs.com/package/react-terminal-viewer">
10
+ <img src="https://img.shields.io/npm/v/react-terminal-viewer/latest"
11
+ data-canonical-src="https://img.shields.io/npm/v/react-terminal-viewer/latest"/>
12
+ </a>
13
+ <img src="https://img.shields.io/npm/l/react-terminal-viewer" data-canonical-src="https://img.shields.io/npm/l/react-terminal-viewer"/>
14
+ </p>
15
+
16
+ ![Preview png](https://gitee.com/oschina/react-terminal-viewer/raw/master/docs/preview.png)
17
+
18
+ ## 功能
19
+
20
+ - 【日志搜索】支持日志搜索,并在输入框实时显示搜索结果;
21
+ - 【日志搜索】支持回车/快捷按钮滚动定位到某一行日志;
22
+ - 【日志搜索】支持变更搜索命中高亮样式;
23
+ - 【日志交互】支持日志置顶,置底;
24
+ - 【日志交互】支持运行中日志自动滚动到底部;
25
+ - 【日志交互】支持选中高亮行,并支持变更高亮样式;
26
+ - 【日志渲染】支持全屏显示;
27
+ - 【日志渲染】支持多种日志组件渲染模式,如自定义关键词高亮渲染,ANSI_escape_code 渲染;
28
+ - 【日志渲染】支持 http 轮询获取日志,支持接口调用重试;
29
+ - 【日志渲染】支持 10W 行以内日志渲染不卡顿;
30
+ - 【日志组件】支持头部组件,实现日志分类的功能;
31
+ - 【日志组件】支持变更组件,如替换置顶,置底图标组件,加载日志组件等;
32
+ - 【日志组件】支持选项可配置式,如请求间隔,高亮模式等;
33
+ - 【日志缓存】使用 `localforage` 缓存已下载的日志,以解决无法查看全量日志的问题;
34
+ - 【日志缓存】支持缓存过期策略的特性,以解决本地缓存可能溢出的问题;
35
+ - 【日志缓存】支持清除缓存,从头开始加载远程日志;
36
+ - 【日志缓存】支持重建缓存时分批写入解决一次行写入过多日志导致崩溃的问题;
37
+ - 【大数据日志】 支持基于 Web Worker 与虚拟 DOM 模式以支持更大的日志数据渲染
38
+
39
+ ## 安装
40
+
41
+ 使用 npm 或 yarn 把这个 package 安装到你的项目依赖中:
42
+
43
+ ```
44
+ npm install react-terminal-viewer
45
+ ```
46
+
47
+
48
+
49
+ ```
50
+ yarn add react-terminal-viewer
51
+ ```
52
+
53
+ ## 使用
54
+
55
+ ```tsx
56
+ import React, { useRef } from 'react';
57
+ import TerminalViewer from 'react-terminal-viewer';
58
+ export default () => {
59
+ const ref = useRef();
60
+ const data = 'echo success';
61
+ return (
62
+ <div style={{ width: '100%', height: '300px' }}>
63
+ <TerminalViewer ref={ref} defaultData={data} />
64
+ </div>
65
+ );
66
+ };
67
+ ```
68
+
69
+ ## 开发
70
+
71
+ ```bash
72
+ $ yarn
73
+ ```
74
+
75
+ 启动开发服务
76
+
77
+ ```bash
78
+ $ yarn start
79
+ ```
80
+
81
+ 构建文档
82
+
83
+ ```bash
84
+ $ yarn docs:build
85
+ ```
86
+
87
+ 执行测试
88
+
89
+ ```bash
90
+ $ yarn test
91
+ ```
92
+
93
+ 构建可发布的包
94
+
95
+ ```bash
96
+ $ yarn build
97
+ ```
98
+
99
+ ## 开启基于 Web Worker 与 虚拟 DOM 的日志组件配置
100
+
101
+ webpack 配置:
102
+
103
+ ```js
104
+ new CopyPlugin({
105
+ patterns: [
106
+ {
107
+ from: path.resolve(__dirname, 'node_modules/react-terminal-viewer/dist/worker'),
108
+ to: path.resolve(__dirname, 'dist/scripts/worker'),
109
+ filter: (file) => file.includes('worker'),
110
+ },
111
+ ],
112
+ }),
113
+ ```
114
+
115
+ 组件使用:
116
+
117
+ ```
118
+ <TerminalViewer virtualDomSupport workerPath="/scripts/worker"/>
119
+ ```
120
+
121
+ ## 发布
122
+ 打标签后使用流水线发布或使用常规方式手动发布:
123
+
124
+ ```bash
125
+ npm version patch && npm publish
126
+ ```
127
+ ## 更新在线地址
128
+
129
+ 合并代码后与打标签后使用流水线发布,使用常规方式合并代码与构建后,手动推送至deploy
130
+
131
+ ## 修复已知问题
132
+
133
+ - 使用 DOM 模式渲染修复搜索命中关键字时无法修改字体前景的问题
134
+ - 使用 1000+ 的提示修复 搜索结果超过 1000+ 时搜索卡顿的问题
135
+
136
+ ## TODO
137
+
138
+ - 【日志交互】支持 hover 复制行锚点(由于无法直接获取可视区域行在全文中的唯一位置,导致锚点难以取到)
139
+ - 【日志交互】支持锚点定位行日志(由于无法直接获取可视区域行在全文中的唯一位置,导致锚点难以取到)
140
+ - 【日志交互】支持 hover 复制行日志
141
+ - 【日志渲染】支持高亮超链接;
142
+ - 【Shell 连接】通过 websocket 连接到运行进程的服务器
143
+
144
+ ## API
145
+
146
+ | 属性名 | 描述 | 类型 | 默认值 |
147
+ | --- | --- | --- | --- |
148
+ | fit | 是否自动拉伸填充容器宽高 | boolean | true |
149
+ | autoScroll | 是否开启自动滚动到底部 | boolean | true |
150
+ | scrollToRow | 自动滚动到某一行,开启后自动滚动到底部失效 | number | -- |
151
+ | logAfter 设置日志后置标签,仅在开启虚拟 DOM 生效 | FunctionComponent<LogAfterProps> 或 ComponentClass<LogAfterProps, any> | -- |
152
+ | refreshable | 是否支持刷新 | boolean | true |
153
+ | searchPlaceholder | 搜索框 placeholder | string | -- |
154
+ | header | 自定义日志头部, null 为不显示默认头部 | ReactNode | -- |
155
+ | inputAddonBefore | 搜索框前的内容 | ReactNode | -- |
156
+ | inputAddonAfter | 搜索框后的内容 | ReactNode | -- |
157
+ | empty | 自定义空文本显示 | ReactNode | -- |
158
+ | icons | 自定义图标 | { search?: ReactNode; up?: ReactNode; down?: ReactNode; clear?: ReactNode; top?: ReactNode; bottom?: ReactNode; fullScreen?: ReactNode; fullScreenExit?: ReactNode; refresh?: ReactNode; loading?: ReactNode; } | -- |
159
+ | toolbar | 自定义工具栏 | ReactNode | -- |
160
+ | showFullScreen | 是否显示全屏图标 | boolean | true |
161
+ | className | 外层样式类名 | string | -- |
162
+ | style | 可用于设置外层容器样式 | object | -- |
163
+ | defaultFullScreen | 默认全屏显示 | boolean | false |
164
+ | defaultData | 用于渲染日志的默认数据,如 "echo 1\r\necho2" | string | '' |
165
+ | defaultTabIndex | 默认打开的标签 | number | 0 |
166
+ | activeTabIndex | 激活的标签, 如果同时设置了 defaultTabIndex 则以此属性为准 | number | 0 |
167
+ | tabs | 多标签配置选项 | { key: string\|number; title?: ReactNode; defaultData?: string; remoteOptions?: IRemoteOptions; cacheOptions?: ICacheOptions; }[] | -- |
168
+ | webLinksSupport | 是否支持渲染超链接 | boolean | true |
169
+ | canvasSupport | 是否使用 canvas 渲染, 开启 canvas 会有更好的性能但可能会遇到更多的问题 | boolean | false |
170
+ | virtualDomSupport | 是否使用自研虚拟 DOM 内核,开启后 terminalOptions, canvasSupport, webLinksSupport 不可用 | boolean | false |
171
+ | workerPath | 日志 web worker 路径, 需配合 CopyPlugin 使用且仅在开启 virtualDomSupport 为 true 时有效 | string | /worker |
172
+ | remoteOptions | 远程加载配置 | IRemoteOptions | -- |
173
+ | cacheOptions | 缓存全局配置,仅在配置远程加载后有效,如 `expires: 60 * 1000` 表示自动清理已过期一分钟的缓存 | ICacheOptions | -- |
174
+ | searchOptions | xterm 搜索选项 | ISearchOptions | -- |
175
+ | highlightOptions | 高亮选项 | IHighlightOptions[] | -- |
176
+ | terminalOptions | xtem.js 配置, https://github.com/xtermjs/xterm.js | ITerminalOptions | -- |
177
+ | extraOptions | 额外的功能选项 { showLineNumber 仅 虚拟 DOM 模式支持} | ExtraOptions | -- |
178
+ | getContainer | 指定 TerminalViewer 挂载的节点,并在容器内展现,开启全屏后无效, false 为挂载在当前位置 | string | HTMLElement | (() => HTMLElement) | 当前节点 |
179
+ | onLoading | 加载状态变更回调函数 | (bool: boolean) => void | -- |
180
+ | onTitleChange | 点击 tab 标题后回调函数 | (index: number) => void | -- |
181
+ | onRefresh | 刷新后的回调函数 | ()=>void | -- |
@@ -0,0 +1,18 @@
1
+ import { IDisposable } from 'xterm';
2
+ export interface IEvent<T, U = void> {
3
+ (listener: (arg1: T, arg2: U) => any): IDisposable;
4
+ }
5
+ export interface IEventEmitter<T, U = void> {
6
+ event: IEvent<T, U>;
7
+ fire(arg1: T, arg2: U): void;
8
+ dispose(): void;
9
+ }
10
+ declare class EventEmitter<T, U = void> implements IEventEmitter<T, U> {
11
+ private _listeners;
12
+ private _event?;
13
+ private _disposed;
14
+ get event(): IEvent<T, U>;
15
+ fire(arg1: T, arg2: U): void;
16
+ dispose(): void;
17
+ }
18
+ export default EventEmitter;
@@ -0,0 +1,64 @@
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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+ /* eslint-disable no-plusplus */
10
+ /* eslint-disable no-underscore-dangle */
11
+ var EventEmitter = /*#__PURE__*/function () {
12
+ function EventEmitter() {
13
+ _classCallCheck(this, EventEmitter);
14
+ _defineProperty(this, "_listeners", []);
15
+ _defineProperty(this, "_event", void 0);
16
+ _defineProperty(this, "_disposed", false);
17
+ }
18
+ _createClass(EventEmitter, [{
19
+ key: "event",
20
+ get: function get() {
21
+ var _this = this;
22
+ if (!this._event) {
23
+ this._event = function (listener) {
24
+ _this._listeners.push(listener);
25
+ var disposable = {
26
+ dispose: function dispose() {
27
+ if (!_this._disposed) {
28
+ for (var i = 0; i < _this._listeners.length; i++) {
29
+ if (_this._listeners[i] === listener) {
30
+ _this._listeners.splice(i, 1);
31
+ return;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ };
37
+ return disposable;
38
+ };
39
+ }
40
+ return this._event;
41
+ }
42
+ }, {
43
+ key: "fire",
44
+ value: function fire(arg1, arg2) {
45
+ var queue = [];
46
+ for (var i = 0; i < this._listeners.length; i++) {
47
+ queue.push(this._listeners[i]);
48
+ }
49
+ for (var _i = 0; _i < queue.length; _i++) {
50
+ queue[_i].call(undefined, arg1, arg2);
51
+ }
52
+ }
53
+ }, {
54
+ key: "dispose",
55
+ value: function dispose() {
56
+ if (this._listeners) {
57
+ this._listeners.length = 0;
58
+ }
59
+ this._disposed = true;
60
+ }
61
+ }]);
62
+ return EventEmitter;
63
+ }();
64
+ export default EventEmitter;
@@ -0,0 +1,26 @@
1
+ import { Terminal, ITerminalAddon } from 'xterm';
2
+ export interface IHighlightOptions {
3
+ keyword: string;
4
+ ignoreSensitive?: boolean;
5
+ decorations: {
6
+ matchForegroundColor?: string;
7
+ matchBackground?: string;
8
+ };
9
+ }
10
+ /**
11
+ * 基于关键字的自定义高亮插件
12
+ */
13
+ declare class HighlightAddon implements ITerminalAddon {
14
+ private _terminal;
15
+ private _cacheDecorations;
16
+ private _highlightTimeout;
17
+ activate(terminal: Terminal): void;
18
+ private _getLineProperty;
19
+ private _decoration;
20
+ private _clearDecoration;
21
+ private _updateHighlight;
22
+ highlight(options: IHighlightOptions[] | undefined): void;
23
+ dispose(): void;
24
+ }
25
+ export { HighlightAddon };
26
+ export default HighlightAddon;
@@ -0,0 +1,188 @@
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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ /* eslint-disable no-restricted-syntax */
9
+ /* eslint-disable prefer-destructuring */
10
+ /* eslint-disable no-cond-assign */
11
+ /* eslint-disable consistent-return */
12
+ /* eslint-disable no-plusplus */
13
+ /* eslint-disable max-len */
14
+ /* eslint-disable no-param-reassign */
15
+ /* eslint-disable class-methods-use-this */
16
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
17
+ /* eslint-disable no-underscore-dangle */
18
+ /**
19
+ * 基于关键字的自定义高亮插件
20
+ */
21
+ var HighlightAddon = /*#__PURE__*/function () {
22
+ function HighlightAddon() {
23
+ _classCallCheck(this, HighlightAddon);
24
+ _defineProperty(this, "_terminal", void 0);
25
+ _defineProperty(this, "_cacheDecorations", void 0);
26
+ _defineProperty(this, "_highlightTimeout", void 0);
27
+ }
28
+ _createClass(HighlightAddon, [{
29
+ key: "activate",
30
+ value: function activate(terminal) {
31
+ this._terminal = terminal;
32
+ }
33
+ }, {
34
+ key: "_getLineProperty",
35
+ value: function _getLineProperty(line) {
36
+ var index = 0;
37
+ var cell = line.getCell(index);
38
+ var width = 0;
39
+ var isAllBgDefault = true;
40
+ var isAllFgDefault = true;
41
+ while (cell) {
42
+ if (!cell.isBgDefault()) {
43
+ isAllBgDefault = false;
44
+ }
45
+ if (!cell.isFgDefault()) {
46
+ isAllFgDefault = false;
47
+ }
48
+ width += cell.getWidth();
49
+ cell = line.getCell(index);
50
+ index++;
51
+ }
52
+ return {
53
+ width: width,
54
+ isAllBgDefault: isAllBgDefault,
55
+ isAllFgDefault: isAllFgDefault
56
+ };
57
+ }
58
+ }, {
59
+ key: "_decoration",
60
+ value: function _decoration(line, lineIndex, matchOption) {
61
+ var _matchOption$decorati, _matchOption$decorati2;
62
+ if (!this._terminal) {
63
+ return;
64
+ }
65
+ if (!(matchOption !== null && matchOption !== void 0 && (_matchOption$decorati = matchOption.decorations) !== null && _matchOption$decorati !== void 0 && _matchOption$decorati.matchBackground) && !(matchOption !== null && matchOption !== void 0 && (_matchOption$decorati2 = matchOption.decorations) !== null && _matchOption$decorati2 !== void 0 && _matchOption$decorati2.matchForegroundColor)) {
66
+ return;
67
+ }
68
+ var terminal = this._terminal;
69
+ var _this$_getLinePropert = this._getLineProperty(line),
70
+ width = _this$_getLinePropert.width,
71
+ isAllBgDefault = _this$_getLinePropert.isAllBgDefault,
72
+ isAllFgDefault = _this$_getLinePropert.isAllFgDefault;
73
+ if (!isAllBgDefault || !isAllFgDefault) {
74
+ return;
75
+ }
76
+ var marker = terminal.registerMarker(-terminal.buffer.active.baseY - terminal.buffer.active.cursorY + lineIndex);
77
+ if (marker) {
78
+ var _matchOption$decorati3, _matchOption$decorati4;
79
+ var decorationOptions = {
80
+ marker: marker,
81
+ x: 0,
82
+ width: width,
83
+ backgroundColor: (_matchOption$decorati3 = matchOption.decorations) === null || _matchOption$decorati3 === void 0 ? void 0 : _matchOption$decorati3.matchBackground,
84
+ foregroundColor: (_matchOption$decorati4 = matchOption.decorations) === null || _matchOption$decorati4 === void 0 ? void 0 : _matchOption$decorati4.matchForegroundColor,
85
+ layer: 'bottom'
86
+ };
87
+ var decoration = terminal.registerDecoration(decorationOptions);
88
+ if (decoration) {
89
+ var _this$_cacheDecoratio;
90
+ decoration === null || decoration === void 0 || decoration.onDispose(function () {
91
+ marker.dispose();
92
+ });
93
+ // 可以在 dom 模式下操作 dom
94
+ // this._highlightDecoration?.onRender((e) => {
95
+ // });
96
+ (_this$_cacheDecoratio = this._cacheDecorations) === null || _this$_cacheDecoratio === void 0 || _this$_cacheDecoratio.set(lineIndex, decoration);
97
+ }
98
+ }
99
+ }
100
+ }, {
101
+ key: "_clearDecoration",
102
+ value: function _clearDecoration() {
103
+ var _this$_cacheDecoratio2, _this$_cacheDecoratio3;
104
+ (_this$_cacheDecoratio2 = this._cacheDecorations) === null || _this$_cacheDecoratio2 === void 0 || _this$_cacheDecoratio2.forEach(function (decoration) {
105
+ decoration.marker.dispose();
106
+ decoration.dispose();
107
+ });
108
+ (_this$_cacheDecoratio3 = this._cacheDecorations) === null || _this$_cacheDecoratio3 === void 0 || _this$_cacheDecoratio3.clear();
109
+ }
110
+ }, {
111
+ key: "_updateHighlight",
112
+ value: function _updateHighlight(options) {
113
+ var _this = this;
114
+ if (!this._terminal) {
115
+ return;
116
+ }
117
+ if (!Array.isArray(options)) {
118
+ return;
119
+ }
120
+ this._clearDecoration();
121
+ var terminal = this._terminal;
122
+ var lineIndex = 0;
123
+ var line = terminal.buffer.active.getLine(lineIndex);
124
+ var prevMatch;
125
+ var _loop = function _loop() {
126
+ var nextLine = terminal.buffer.active.getLine(lineIndex + 1);
127
+ var lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
128
+ var string = line.translateToString(!lineWrapsToNext);
129
+ if (string) {
130
+ if (line.isWrapped && prevMatch) {
131
+ _this._decoration(line, lineIndex, prevMatch);
132
+ } else {
133
+ var matchOption = options.find(function (option) {
134
+ var keyword = option.keyword || '';
135
+ if (option.ignoreSensitive) {
136
+ var lowerString = string.toLowerCase();
137
+ return lowerString.includes(keyword.toLowerCase()) || lowerString.includes(keyword);
138
+ }
139
+ return string.includes(keyword);
140
+ });
141
+ prevMatch = matchOption;
142
+ _this._decoration(line, lineIndex, matchOption);
143
+ }
144
+ }
145
+ lineIndex++;
146
+ line = nextLine;
147
+ };
148
+ while (line) {
149
+ _loop();
150
+ }
151
+ }
152
+ }, {
153
+ key: "highlight",
154
+ value: function highlight(options) {
155
+ var _this2 = this;
156
+ if (!this._terminal) {
157
+ return;
158
+ }
159
+ if (!Array.isArray(options)) {
160
+ return;
161
+ }
162
+ this._cacheDecorations = new Map();
163
+ var terminal = this._terminal;
164
+ terminal.onWriteParsed(function () {
165
+ clearTimeout(_this2._highlightTimeout);
166
+ _this2._highlightTimeout = setTimeout(function () {
167
+ _this2._updateHighlight(options);
168
+ }, 0);
169
+ // this._clearDecoration();
170
+ });
171
+ terminal.onResize(function () {
172
+ clearTimeout(_this2._highlightTimeout);
173
+ _this2._highlightTimeout = setTimeout(function () {
174
+ _this2._updateHighlight(options);
175
+ }, 0);
176
+ });
177
+ }
178
+ }, {
179
+ key: "dispose",
180
+ value: function dispose() {
181
+ clearTimeout(this._highlightTimeout);
182
+ this._cacheDecorations = undefined;
183
+ }
184
+ }]);
185
+ return HighlightAddon;
186
+ }();
187
+ export { HighlightAddon };
188
+ export default HighlightAddon;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * 从 https://github.com/xtermjs/xterm.js/blob/master/addons/xterm-addon-search/src/SearchAddon.ts 复制以解决部分问题
3
+ */
4
+ import { Terminal, ITerminalAddon } from 'xterm';
5
+ export interface ISearchOptions {
6
+ regex?: boolean;
7
+ wholeWord?: boolean;
8
+ caseSensitive?: boolean;
9
+ incremental?: boolean;
10
+ decorations?: ISearchDecorationOptions;
11
+ noScroll?: boolean;
12
+ }
13
+ interface ISearchDecorationOptions {
14
+ matchForegroundColor?: string;
15
+ matchBackground?: string;
16
+ matchBorder?: string;
17
+ matchOverviewRuler: string;
18
+ activeMatchBackground?: string;
19
+ activeMatchBorder?: string;
20
+ activeMatchColorOverviewRuler: string;
21
+ }
22
+ export interface ISearchPosition {
23
+ startCol: number;
24
+ startRow: number;
25
+ }
26
+ export interface ISearchResult {
27
+ term: string;
28
+ col: number;
29
+ row: number;
30
+ size: number;
31
+ }
32
+ export declare class SearchAddon implements ITerminalAddon {
33
+ private _terminal;
34
+ private _cachedSearchTerm;
35
+ private _selectedDecoration;
36
+ private _resultDecorations;
37
+ private _searchResults;
38
+ private _onDataDisposable;
39
+ private _onResizeDisposable;
40
+ private _lastSearchOptions;
41
+ private _highlightTimeout;
42
+ /**
43
+ * translateBufferLineToStringWithWrap is a fairly expensive call.
44
+ * We memoize the calls into an array that has a time based ttl.
45
+ * _linesCache is also invalidated when the terminal cursor moves.
46
+ */
47
+ private _linesCache;
48
+ private _linesCacheTimeoutId;
49
+ private _cursorMoveListener;
50
+ private _resizeListener;
51
+ private _resultIndex;
52
+ private readonly _onDidChangeResults;
53
+ readonly onDidChangeResults: import("./EventEmiter").IEvent<{
54
+ resultIndex: number;
55
+ resultCount: number;
56
+ } | undefined, void>;
57
+ activate(terminal: Terminal): void;
58
+ private _updateMatches;
59
+ dispose(): void;
60
+ clearDecorations(retainCachedSearchTerm?: boolean): void;
61
+ clearActiveDecoration(): void;
62
+ /**
63
+ * Find the next instance of the term, then scroll to and select it. If it
64
+ * doesn't exist, do nothing.
65
+ * @param term The search term.
66
+ * @param searchOptions Search options.
67
+ * @return Whether a result was found.
68
+ */
69
+ findNext(term: string, searchOptions?: ISearchOptions): boolean;
70
+ private _highlightAllMatches;
71
+ private _find;
72
+ private _findNextAndSelect;
73
+ /**
74
+ * Find the previous instance of the term, then scroll to and select it. If it
75
+ * doesn't exist, do nothing.
76
+ * @param term The search term.
77
+ * @param searchOptions Search options.
78
+ * @return Whether a result was found.
79
+ */
80
+ findPrevious(term: string, searchOptions?: ISearchOptions): boolean;
81
+ private _fireResults;
82
+ private _findPreviousAndSelect;
83
+ /**
84
+ * Sets up a line cache with a ttl
85
+ */
86
+ private _initLinesCache;
87
+ private _destroyLinesCache;
88
+ /**
89
+ * A found substring is a whole word if it doesn't have an alphanumeric character directly adjacent to it.
90
+ * @param searchIndex starting indext of the potential whole word substring
91
+ * @param line entire string in which the potential whole word was found
92
+ * @param term the substring that starts at searchIndex
93
+ */
94
+ private _isWholeWord;
95
+ /**
96
+ * Searches a line for a search term. Takes the provided terminal line and searches the text line, which may contain
97
+ * subsequent terminal lines if the text is wrapped. If the provided line number is part of a wrapped text line that
98
+ * started on an earlier line then it is skipped since it will be properly searched when the terminal line that the
99
+ * text starts on is searched.
100
+ * @param term The search term.
101
+ * @param position The position to start the search.
102
+ * @param searchOptions Search options.
103
+ * @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left.
104
+ * @return The search result if it was found.
105
+ */
106
+ protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions?: ISearchOptions, isReverseSearch?: boolean): ISearchResult | undefined;
107
+ private _stringLengthToBufferSize;
108
+ private _bufferColsToStringOffset;
109
+ /**
110
+ * Translates a buffer line to a string, including subsequent lines if they are wraps.
111
+ * Wide characters will count as two columns in the resulting string. This
112
+ * function is useful for getting the actual text underneath the raw selection
113
+ * position.
114
+ * @param line The line being translated.
115
+ * @param trimRight Whether to trim whitespace to the right.
116
+ */
117
+ private _translateBufferLineToStringWithWrap;
118
+ /**
119
+ * Selects and scrolls to a result.
120
+ * @param result The result to select.
121
+ * @return Whether a result was selected.
122
+ */
123
+ private _selectResult;
124
+ /**
125
+ * Applies styles to the decoration when it is rendered
126
+ * @param element the decoration's element
127
+ * @param backgroundColor the background color to apply
128
+ * @param borderColor the border color to apply
129
+ * @returns
130
+ */
131
+ private _applyStyles;
132
+ /**
133
+ * Creates a decoration for the result and applies styles
134
+ * @param result the search result for which to create the decoration
135
+ * @param options the options for the decoration
136
+ * @returns the {@link IDecoration} or undefined if the marker has already been disposed of
137
+ */
138
+ private _createResultDecoration;
139
+ }
140
+ export {};