react-terminal-viewer
Version:
<h1 align="center"> react-terminal-viewer </h1>
63 lines • 1.61 kB
JavaScript
/* eslint-disable no-restricted-globals */
import WebWorkerServer from "./WebWokerServer";
import LimitMap from "./LimitMap";
import Logs from "./Logs";
var server = new WebWorkerServer(self);
var logsInstanceMap = new LimitMap({
limit: 8
});
server.on('highlight-log', function (ctx, _ref) {
var id = _ref.id,
string = _ref.string;
if (!logsInstanceMap.has(id)) {
logsInstanceMap.set(id, new Logs({
id: id,
string: string
}));
}
var instance = logsInstanceMap.get(id);
ctx.send('highlight-log-success', {
id: id,
logs: instance === null || instance === void 0 ? void 0 : instance.getArrayData()
});
});
server.on('search-log', function (ctx, _ref2) {
var id = _ref2.id,
searchId = _ref2.searchId,
_ref2$keyword = _ref2.keyword,
keyword = _ref2$keyword === void 0 ? '' : _ref2$keyword,
hlIndex = _ref2.hlIndex,
_ref2$string = _ref2.string,
string = _ref2$string === void 0 ? '' : _ref2$string,
options = _ref2.options;
if (!keyword) {
ctx.send('search-log-success', {
id: id,
searchId: searchId,
searcherResult: {
map: {},
count: 0,
markedKey: 0
}
});
return;
}
if (!logsInstanceMap.has(id)) {
logsInstanceMap.set(id, new Logs({
id: id,
string: string
}));
}
var instance = logsInstanceMap.get(id);
if (instance) {
ctx.send('search-log-success', {
id: id,
searchId: searchId,
searcherResult: instance.mark(keyword, hlIndex, options) || {
map: {},
count: 0,
markedKey: 0
}
});
}
});