@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.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/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blessed - a high-level terminal interface library for node.js
|
|
3
|
+
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
|
|
4
|
+
* https://github.com/chjj/blessed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Blessed
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function blessed() {
|
|
12
|
+
return blessed.program.apply(null, arguments);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
blessed.program = blessed.Program = require('./program');
|
|
16
|
+
blessed.tput = blessed.Tput = require('./tput');
|
|
17
|
+
blessed.widget = require('./widget');
|
|
18
|
+
blessed.colors = require('./colors');
|
|
19
|
+
blessed.unicode = require('./unicode');
|
|
20
|
+
blessed.helpers = require('./helpers');
|
|
21
|
+
|
|
22
|
+
blessed.helpers.sprintf = blessed.tput.sprintf;
|
|
23
|
+
blessed.helpers.tryRead = blessed.tput.tryRead;
|
|
24
|
+
blessed.helpers.merge(blessed, blessed.helpers);
|
|
25
|
+
|
|
26
|
+
blessed.helpers.merge(blessed, blessed.widget);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Expose
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
module.exports = blessed;
|
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* colors.js - color-related functions for blessed.
|
|
3
|
+
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
|
|
4
|
+
* https://github.com/chjj/blessed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
exports.match = function(r1, g1, b1) {
|
|
8
|
+
if (typeof r1 === 'string') {
|
|
9
|
+
var hex = r1;
|
|
10
|
+
if (hex[0] !== '#') {
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
hex = exports.hexToRGB(hex);
|
|
14
|
+
r1 = hex[0], g1 = hex[1], b1 = hex[2];
|
|
15
|
+
} else if (Array.isArray(r1)) {
|
|
16
|
+
b1 = r1[2], g1 = r1[1], r1 = r1[0];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var hash = (r1 << 16) | (g1 << 8) | b1;
|
|
20
|
+
|
|
21
|
+
if (exports._cache[hash] != null) {
|
|
22
|
+
return exports._cache[hash];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var ldiff = Infinity
|
|
26
|
+
, li = -1
|
|
27
|
+
, i = 0
|
|
28
|
+
, c
|
|
29
|
+
, r2
|
|
30
|
+
, g2
|
|
31
|
+
, b2
|
|
32
|
+
, diff;
|
|
33
|
+
|
|
34
|
+
for (; i < exports.vcolors.length; i++) {
|
|
35
|
+
c = exports.vcolors[i];
|
|
36
|
+
r2 = c[0];
|
|
37
|
+
g2 = c[1];
|
|
38
|
+
b2 = c[2];
|
|
39
|
+
|
|
40
|
+
diff = colorDistance(r1, g1, b1, r2, g2, b2);
|
|
41
|
+
|
|
42
|
+
if (diff === 0) {
|
|
43
|
+
li = i;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (diff < ldiff) {
|
|
48
|
+
ldiff = diff;
|
|
49
|
+
li = i;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return exports._cache[hash] = li;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.RGBToHex = function(r, g, b) {
|
|
57
|
+
if (Array.isArray(r)) {
|
|
58
|
+
b = r[2], g = r[1], r = r[0];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function hex(n) {
|
|
62
|
+
n = n.toString(16);
|
|
63
|
+
if (n.length < 2) n = '0' + n;
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return '#' + hex(r) + hex(g) + hex(b);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.hexToRGB = function(hex) {
|
|
71
|
+
if (hex.length === 4) {
|
|
72
|
+
hex = hex[0]
|
|
73
|
+
+ hex[1] + hex[1]
|
|
74
|
+
+ hex[2] + hex[2]
|
|
75
|
+
+ hex[3] + hex[3];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var col = parseInt(hex.substring(1), 16)
|
|
79
|
+
, r = (col >> 16) & 0xff
|
|
80
|
+
, g = (col >> 8) & 0xff
|
|
81
|
+
, b = col & 0xff;
|
|
82
|
+
|
|
83
|
+
return [r, g, b];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// As it happens, comparing how similar two colors are is really hard. Here is
|
|
87
|
+
// one of the simplest solutions, which doesn't require conversion to another
|
|
88
|
+
// color space, posted on stackoverflow[1]. Maybe someone better at math can
|
|
89
|
+
// propose a superior solution.
|
|
90
|
+
// [1] http://stackoverflow.com/questions/1633828
|
|
91
|
+
|
|
92
|
+
function colorDistance(r1, g1, b1, r2, g2, b2) {
|
|
93
|
+
return Math.pow(30 * (r1 - r2), 2)
|
|
94
|
+
+ Math.pow(59 * (g1 - g2), 2)
|
|
95
|
+
+ Math.pow(11 * (b1 - b2), 2);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// This might work well enough for a terminal's colors: treat RGB as XYZ in a
|
|
99
|
+
// 3-dimensional space and go midway between the two points.
|
|
100
|
+
exports.mixColors = function(c1, c2, alpha) {
|
|
101
|
+
// if (c1 === 0x1ff) return c1;
|
|
102
|
+
// if (c2 === 0x1ff) return c1;
|
|
103
|
+
if (c1 === 0x1ff) c1 = 0;
|
|
104
|
+
if (c2 === 0x1ff) c2 = 0;
|
|
105
|
+
if (alpha == null) alpha = 0.5;
|
|
106
|
+
|
|
107
|
+
c1 = exports.vcolors[c1];
|
|
108
|
+
var r1 = c1[0];
|
|
109
|
+
var g1 = c1[1];
|
|
110
|
+
var b1 = c1[2];
|
|
111
|
+
|
|
112
|
+
c2 = exports.vcolors[c2];
|
|
113
|
+
var r2 = c2[0];
|
|
114
|
+
var g2 = c2[1];
|
|
115
|
+
var b2 = c2[2];
|
|
116
|
+
|
|
117
|
+
r1 += (r2 - r1) * alpha | 0;
|
|
118
|
+
g1 += (g2 - g1) * alpha | 0;
|
|
119
|
+
b1 += (b2 - b1) * alpha | 0;
|
|
120
|
+
|
|
121
|
+
return exports.match([r1, g1, b1]);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
exports.blend = function blend(attr, attr2, alpha) {
|
|
125
|
+
var name, i, c, nc;
|
|
126
|
+
|
|
127
|
+
var bg = attr & 0x1ff;
|
|
128
|
+
if (attr2 != null) {
|
|
129
|
+
var bg2 = attr2 & 0x1ff;
|
|
130
|
+
if (bg === 0x1ff) bg = 0;
|
|
131
|
+
if (bg2 === 0x1ff) bg2 = 0;
|
|
132
|
+
bg = exports.mixColors(bg, bg2, alpha);
|
|
133
|
+
} else {
|
|
134
|
+
if (blend._cache[bg] != null) {
|
|
135
|
+
bg = blend._cache[bg];
|
|
136
|
+
// } else if (bg < 8) {
|
|
137
|
+
// bg += 8;
|
|
138
|
+
} else if (bg >= 8 && bg <= 15) {
|
|
139
|
+
bg -= 8;
|
|
140
|
+
} else {
|
|
141
|
+
name = exports.ncolors[bg];
|
|
142
|
+
if (name) {
|
|
143
|
+
for (i = 0; i < exports.ncolors.length; i++) {
|
|
144
|
+
if (name === exports.ncolors[i] && i !== bg) {
|
|
145
|
+
c = exports.vcolors[bg];
|
|
146
|
+
nc = exports.vcolors[i];
|
|
147
|
+
if (nc[0] + nc[1] + nc[2] < c[0] + c[1] + c[2]) {
|
|
148
|
+
blend._cache[bg] = i;
|
|
149
|
+
bg = i;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
attr &= ~0x1ff;
|
|
159
|
+
attr |= bg;
|
|
160
|
+
|
|
161
|
+
var fg = (attr >> 9) & 0x1ff;
|
|
162
|
+
if (attr2 != null) {
|
|
163
|
+
var fg2 = (attr2 >> 9) & 0x1ff;
|
|
164
|
+
// 0, 7, 188, 231, 251
|
|
165
|
+
if (fg === 0x1ff) {
|
|
166
|
+
// XXX workaround
|
|
167
|
+
fg = 248;
|
|
168
|
+
} else {
|
|
169
|
+
if (fg === 0x1ff) fg = 7;
|
|
170
|
+
if (fg2 === 0x1ff) fg2 = 7;
|
|
171
|
+
fg = exports.mixColors(fg, fg2, alpha);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
if (blend._cache[fg] != null) {
|
|
175
|
+
fg = blend._cache[fg];
|
|
176
|
+
// } else if (fg < 8) {
|
|
177
|
+
// fg += 8;
|
|
178
|
+
} else if (fg >= 8 && fg <= 15) {
|
|
179
|
+
fg -= 8;
|
|
180
|
+
} else {
|
|
181
|
+
name = exports.ncolors[fg];
|
|
182
|
+
if (name) {
|
|
183
|
+
for (i = 0; i < exports.ncolors.length; i++) {
|
|
184
|
+
if (name === exports.ncolors[i] && i !== fg) {
|
|
185
|
+
c = exports.vcolors[fg];
|
|
186
|
+
nc = exports.vcolors[i];
|
|
187
|
+
if (nc[0] + nc[1] + nc[2] < c[0] + c[1] + c[2]) {
|
|
188
|
+
blend._cache[fg] = i;
|
|
189
|
+
fg = i;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
attr &= ~(0x1ff << 9);
|
|
199
|
+
attr |= fg << 9;
|
|
200
|
+
|
|
201
|
+
return attr;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
exports.blend._cache = {};
|
|
205
|
+
|
|
206
|
+
exports._cache = {};
|
|
207
|
+
|
|
208
|
+
exports.reduce = function(color, total) {
|
|
209
|
+
if (color >= 16 && total <= 16) {
|
|
210
|
+
color = exports.ccolors[color];
|
|
211
|
+
} else if (color >= 8 && total <= 8) {
|
|
212
|
+
color -= 8;
|
|
213
|
+
} else if (color >= 2 && total <= 2) {
|
|
214
|
+
color %= 2;
|
|
215
|
+
}
|
|
216
|
+
return color;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// XTerm Colors
|
|
220
|
+
// These were actually tough to track down. The xterm source only uses color
|
|
221
|
+
// keywords. The X11 source needed to be examined to find the actual values.
|
|
222
|
+
// They then had to be mapped to rgb values and then converted to hex values.
|
|
223
|
+
exports.xterm = [
|
|
224
|
+
'#000000', // black
|
|
225
|
+
'#cd0000', // red3
|
|
226
|
+
'#00cd00', // green3
|
|
227
|
+
'#cdcd00', // yellow3
|
|
228
|
+
'#0000ee', // blue2
|
|
229
|
+
'#cd00cd', // magenta3
|
|
230
|
+
'#00cdcd', // cyan3
|
|
231
|
+
'#e5e5e5', // gray90
|
|
232
|
+
'#7f7f7f', // gray50
|
|
233
|
+
'#ff0000', // red
|
|
234
|
+
'#00ff00', // green
|
|
235
|
+
'#ffff00', // yellow
|
|
236
|
+
'#5c5cff', // rgb:5c/5c/ff
|
|
237
|
+
'#ff00ff', // magenta
|
|
238
|
+
'#00ffff', // cyan
|
|
239
|
+
'#ffffff' // white
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
// Seed all 256 colors. Assume xterm defaults.
|
|
243
|
+
// Ported from the xterm color generation script.
|
|
244
|
+
exports.colors = (function() {
|
|
245
|
+
var cols = exports.colors = []
|
|
246
|
+
, _cols = exports.vcolors = []
|
|
247
|
+
, r
|
|
248
|
+
, g
|
|
249
|
+
, b
|
|
250
|
+
, i
|
|
251
|
+
, l;
|
|
252
|
+
|
|
253
|
+
function hex(n) {
|
|
254
|
+
n = n.toString(16);
|
|
255
|
+
if (n.length < 2) n = '0' + n;
|
|
256
|
+
return n;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function push(i, r, g, b) {
|
|
260
|
+
cols[i] = '#' + hex(r) + hex(g) + hex(b);
|
|
261
|
+
_cols[i] = [r, g, b];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 0 - 15
|
|
265
|
+
exports.xterm.forEach(function(c, i) {
|
|
266
|
+
c = parseInt(c.substring(1), 16);
|
|
267
|
+
push(i, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// 16 - 231
|
|
271
|
+
for (r = 0; r < 6; r++) {
|
|
272
|
+
for (g = 0; g < 6; g++) {
|
|
273
|
+
for (b = 0; b < 6; b++) {
|
|
274
|
+
i = 16 + (r * 36) + (g * 6) + b;
|
|
275
|
+
push(i,
|
|
276
|
+
r ? (r * 40 + 55) : 0,
|
|
277
|
+
g ? (g * 40 + 55) : 0,
|
|
278
|
+
b ? (b * 40 + 55) : 0);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 232 - 255 are grey.
|
|
284
|
+
for (g = 0; g < 24; g++) {
|
|
285
|
+
l = (g * 10) + 8;
|
|
286
|
+
i = 232 + g;
|
|
287
|
+
push(i, l, l, l);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return cols;
|
|
291
|
+
})();
|
|
292
|
+
|
|
293
|
+
// Map higher colors to the first 8 colors.
|
|
294
|
+
// This allows translation of high colors to low colors on 8-color terminals.
|
|
295
|
+
exports.ccolors = (function() {
|
|
296
|
+
var _cols = exports.vcolors.slice()
|
|
297
|
+
, cols = exports.colors.slice()
|
|
298
|
+
, out;
|
|
299
|
+
|
|
300
|
+
exports.vcolors = exports.vcolors.slice(0, 8);
|
|
301
|
+
exports.colors = exports.colors.slice(0, 8);
|
|
302
|
+
|
|
303
|
+
out = cols.map(exports.match);
|
|
304
|
+
|
|
305
|
+
exports.colors = cols;
|
|
306
|
+
exports.vcolors = _cols;
|
|
307
|
+
exports.ccolors = out;
|
|
308
|
+
|
|
309
|
+
return out;
|
|
310
|
+
})();
|
|
311
|
+
|
|
312
|
+
var colorNames = exports.colorNames = {
|
|
313
|
+
// special
|
|
314
|
+
default: -1,
|
|
315
|
+
normal: -1,
|
|
316
|
+
bg: -1,
|
|
317
|
+
fg: -1,
|
|
318
|
+
// normal
|
|
319
|
+
black: 0,
|
|
320
|
+
red: 1,
|
|
321
|
+
green: 2,
|
|
322
|
+
yellow: 3,
|
|
323
|
+
blue: 4,
|
|
324
|
+
magenta: 5,
|
|
325
|
+
cyan: 6,
|
|
326
|
+
white: 7,
|
|
327
|
+
// light
|
|
328
|
+
lightblack: 8,
|
|
329
|
+
lightred: 9,
|
|
330
|
+
lightgreen: 10,
|
|
331
|
+
lightyellow: 11,
|
|
332
|
+
lightblue: 12,
|
|
333
|
+
lightmagenta: 13,
|
|
334
|
+
lightcyan: 14,
|
|
335
|
+
lightwhite: 15,
|
|
336
|
+
// bright
|
|
337
|
+
brightblack: 8,
|
|
338
|
+
brightred: 9,
|
|
339
|
+
brightgreen: 10,
|
|
340
|
+
brightyellow: 11,
|
|
341
|
+
brightblue: 12,
|
|
342
|
+
brightmagenta: 13,
|
|
343
|
+
brightcyan: 14,
|
|
344
|
+
brightwhite: 15,
|
|
345
|
+
// alternate spellings
|
|
346
|
+
grey: 8,
|
|
347
|
+
gray: 8,
|
|
348
|
+
lightgrey: 7,
|
|
349
|
+
lightgray: 7,
|
|
350
|
+
brightgrey: 7,
|
|
351
|
+
brightgray: 7
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
exports.convert = function(color) {
|
|
355
|
+
if (typeof color === 'number') {
|
|
356
|
+
;
|
|
357
|
+
} else if (typeof color === 'string') {
|
|
358
|
+
color = color.replace(/[\- ]/g, '');
|
|
359
|
+
if (colorNames[color] != null) {
|
|
360
|
+
color = colorNames[color];
|
|
361
|
+
} else {
|
|
362
|
+
color = exports.match(color);
|
|
363
|
+
}
|
|
364
|
+
} else if (Array.isArray(color)) {
|
|
365
|
+
color = exports.match(color);
|
|
366
|
+
} else {
|
|
367
|
+
color = -1;
|
|
368
|
+
}
|
|
369
|
+
return color !== -1 ? color : 0x1ff;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// Map higher colors to the first 8 colors.
|
|
373
|
+
// This allows translation of high colors to low colors on 8-color terminals.
|
|
374
|
+
// Why the hell did I do this by hand?
|
|
375
|
+
exports.ccolors = {
|
|
376
|
+
blue: [
|
|
377
|
+
4,
|
|
378
|
+
12,
|
|
379
|
+
[17, 21],
|
|
380
|
+
[24, 27],
|
|
381
|
+
[31, 33],
|
|
382
|
+
[38, 39],
|
|
383
|
+
45,
|
|
384
|
+
[54, 57],
|
|
385
|
+
[60, 63],
|
|
386
|
+
[67, 69],
|
|
387
|
+
[74, 75],
|
|
388
|
+
81,
|
|
389
|
+
[91, 93],
|
|
390
|
+
[97, 99],
|
|
391
|
+
[103, 105],
|
|
392
|
+
[110, 111],
|
|
393
|
+
117,
|
|
394
|
+
[128, 129],
|
|
395
|
+
[134, 135],
|
|
396
|
+
[140, 141],
|
|
397
|
+
[146, 147],
|
|
398
|
+
153,
|
|
399
|
+
165,
|
|
400
|
+
171,
|
|
401
|
+
177,
|
|
402
|
+
183,
|
|
403
|
+
189
|
|
404
|
+
],
|
|
405
|
+
|
|
406
|
+
green: [
|
|
407
|
+
2,
|
|
408
|
+
10,
|
|
409
|
+
22,
|
|
410
|
+
[28, 29],
|
|
411
|
+
[34, 36],
|
|
412
|
+
[40, 43],
|
|
413
|
+
[46, 50],
|
|
414
|
+
[64, 65],
|
|
415
|
+
[70, 72],
|
|
416
|
+
[76, 79],
|
|
417
|
+
[82, 86],
|
|
418
|
+
[106, 108],
|
|
419
|
+
[112, 115],
|
|
420
|
+
[118, 122],
|
|
421
|
+
[148, 151],
|
|
422
|
+
[154, 158],
|
|
423
|
+
[190, 194]
|
|
424
|
+
],
|
|
425
|
+
|
|
426
|
+
cyan: [
|
|
427
|
+
6,
|
|
428
|
+
14,
|
|
429
|
+
23,
|
|
430
|
+
30,
|
|
431
|
+
37,
|
|
432
|
+
44,
|
|
433
|
+
51,
|
|
434
|
+
66,
|
|
435
|
+
73,
|
|
436
|
+
80,
|
|
437
|
+
87,
|
|
438
|
+
109,
|
|
439
|
+
116,
|
|
440
|
+
123,
|
|
441
|
+
152,
|
|
442
|
+
159,
|
|
443
|
+
195
|
|
444
|
+
],
|
|
445
|
+
|
|
446
|
+
red: [
|
|
447
|
+
1,
|
|
448
|
+
9,
|
|
449
|
+
52,
|
|
450
|
+
[88, 89],
|
|
451
|
+
[94, 95],
|
|
452
|
+
[124, 126],
|
|
453
|
+
[130, 132],
|
|
454
|
+
[136, 138],
|
|
455
|
+
[160, 163],
|
|
456
|
+
[166, 169],
|
|
457
|
+
[172, 175],
|
|
458
|
+
[178, 181],
|
|
459
|
+
[196, 200],
|
|
460
|
+
[202, 206],
|
|
461
|
+
[208, 212],
|
|
462
|
+
[214, 218],
|
|
463
|
+
[220, 224]
|
|
464
|
+
],
|
|
465
|
+
|
|
466
|
+
magenta: [
|
|
467
|
+
5,
|
|
468
|
+
13,
|
|
469
|
+
53,
|
|
470
|
+
90,
|
|
471
|
+
96,
|
|
472
|
+
127,
|
|
473
|
+
133,
|
|
474
|
+
139,
|
|
475
|
+
164,
|
|
476
|
+
170,
|
|
477
|
+
176,
|
|
478
|
+
182,
|
|
479
|
+
201,
|
|
480
|
+
207,
|
|
481
|
+
213,
|
|
482
|
+
219,
|
|
483
|
+
225
|
|
484
|
+
],
|
|
485
|
+
|
|
486
|
+
yellow: [
|
|
487
|
+
3,
|
|
488
|
+
11,
|
|
489
|
+
58,
|
|
490
|
+
[100, 101],
|
|
491
|
+
[142, 144],
|
|
492
|
+
[184, 187],
|
|
493
|
+
[226, 230]
|
|
494
|
+
],
|
|
495
|
+
|
|
496
|
+
black: [
|
|
497
|
+
0,
|
|
498
|
+
8,
|
|
499
|
+
16,
|
|
500
|
+
59,
|
|
501
|
+
102,
|
|
502
|
+
[232, 243]
|
|
503
|
+
],
|
|
504
|
+
|
|
505
|
+
white: [
|
|
506
|
+
7,
|
|
507
|
+
15,
|
|
508
|
+
145,
|
|
509
|
+
188,
|
|
510
|
+
231,
|
|
511
|
+
[244, 255]
|
|
512
|
+
]
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
exports.ncolors = [];
|
|
516
|
+
|
|
517
|
+
Object.keys(exports.ccolors).forEach(function(name) {
|
|
518
|
+
exports.ccolors[name].forEach(function(offset) {
|
|
519
|
+
if (typeof offset === 'number') {
|
|
520
|
+
exports.ncolors[offset] = name;
|
|
521
|
+
exports.ccolors[offset] = exports.colorNames[name];
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
for (var i = offset[0], l = offset[1]; i <= l; i++) {
|
|
525
|
+
exports.ncolors[i] = name;
|
|
526
|
+
exports.ccolors[i] = exports.colorNames[name];
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
delete exports.ccolors[name];
|
|
530
|
+
});
|