@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,599 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* list.js - list element for blessed
|
|
3
|
+
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
|
|
4
|
+
* https://github.com/chjj/blessed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Modules
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var helpers = require('../helpers');
|
|
12
|
+
|
|
13
|
+
var Node = require('./node');
|
|
14
|
+
var Box = require('./box');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* List
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function List(options) {
|
|
21
|
+
var self = this;
|
|
22
|
+
|
|
23
|
+
if (!(this instanceof Node)) {
|
|
24
|
+
return new List(options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
options = options || {};
|
|
28
|
+
|
|
29
|
+
options.ignoreKeys = true;
|
|
30
|
+
// Possibly put this here: this.items = [];
|
|
31
|
+
options.scrollable = true;
|
|
32
|
+
Box.call(this, options);
|
|
33
|
+
|
|
34
|
+
this.value = '';
|
|
35
|
+
this.items = [];
|
|
36
|
+
this.ritems = [];
|
|
37
|
+
this.selected = 0;
|
|
38
|
+
this._isList = true;
|
|
39
|
+
|
|
40
|
+
if (!this.style.selected) {
|
|
41
|
+
this.style.selected = {};
|
|
42
|
+
this.style.selected.bg = options.selectedBg;
|
|
43
|
+
this.style.selected.fg = options.selectedFg;
|
|
44
|
+
this.style.selected.bold = options.selectedBold;
|
|
45
|
+
this.style.selected.underline = options.selectedUnderline;
|
|
46
|
+
this.style.selected.blink = options.selectedBlink;
|
|
47
|
+
this.style.selected.inverse = options.selectedInverse;
|
|
48
|
+
this.style.selected.invisible = options.selectedInvisible;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!this.style.item) {
|
|
52
|
+
this.style.item = {};
|
|
53
|
+
this.style.item.bg = options.itemBg;
|
|
54
|
+
this.style.item.fg = options.itemFg;
|
|
55
|
+
this.style.item.bold = options.itemBold;
|
|
56
|
+
this.style.item.underline = options.itemUnderline;
|
|
57
|
+
this.style.item.blink = options.itemBlink;
|
|
58
|
+
this.style.item.inverse = options.itemInverse;
|
|
59
|
+
this.style.item.invisible = options.itemInvisible;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Legacy: for apps written before the addition of item attributes.
|
|
63
|
+
['bg', 'fg', 'bold', 'underline',
|
|
64
|
+
'blink', 'inverse', 'invisible'].forEach(function(name) {
|
|
65
|
+
if (self.style[name] != null && self.style.item[name] == null) {
|
|
66
|
+
self.style.item[name] = self.style[name];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (this.options.itemHoverBg) {
|
|
71
|
+
this.options.itemHoverEffects = { bg: this.options.itemHoverBg };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.options.itemHoverEffects) {
|
|
75
|
+
this.style.item.hover = this.options.itemHoverEffects;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (this.options.itemFocusEffects) {
|
|
79
|
+
this.style.item.focus = this.options.itemFocusEffects;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.interactive = options.interactive !== false;
|
|
83
|
+
|
|
84
|
+
this.mouse = options.mouse || false;
|
|
85
|
+
|
|
86
|
+
if (options.items) {
|
|
87
|
+
this.ritems = options.items;
|
|
88
|
+
options.items.forEach(this.add.bind(this));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.select(0);
|
|
92
|
+
|
|
93
|
+
if (options.mouse) {
|
|
94
|
+
this.screen._listenMouse(this);
|
|
95
|
+
this.on('element wheeldown', function() {
|
|
96
|
+
self.select(self.selected + 2);
|
|
97
|
+
self.screen.render();
|
|
98
|
+
});
|
|
99
|
+
this.on('element wheelup', function() {
|
|
100
|
+
self.select(self.selected - 2);
|
|
101
|
+
self.screen.render();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (options.keys) {
|
|
106
|
+
this.on('keypress', function(ch, key) {
|
|
107
|
+
if (key.name === 'up' || (options.vi && key.name === 'k')) {
|
|
108
|
+
self.up();
|
|
109
|
+
self.screen.render();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (key.name === 'down' || (options.vi && key.name === 'j')) {
|
|
113
|
+
self.down();
|
|
114
|
+
self.screen.render();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (key.name === 'enter'
|
|
118
|
+
|| (options.vi && key.name === 'l' && !key.shift)) {
|
|
119
|
+
self.enterSelected();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (key.name === 'escape' || (options.vi && key.name === 'q')) {
|
|
123
|
+
self.cancelSelected();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (options.vi && key.name === 'u' && key.ctrl) {
|
|
127
|
+
self.move(-((self.height - self.iheight) / 2) | 0);
|
|
128
|
+
self.screen.render();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (options.vi && key.name === 'd' && key.ctrl) {
|
|
132
|
+
self.move((self.height - self.iheight) / 2 | 0);
|
|
133
|
+
self.screen.render();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (options.vi && key.name === 'b' && key.ctrl) {
|
|
137
|
+
self.move(-(self.height - self.iheight));
|
|
138
|
+
self.screen.render();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (options.vi && key.name === 'f' && key.ctrl) {
|
|
142
|
+
self.move(self.height - self.iheight);
|
|
143
|
+
self.screen.render();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (options.vi && key.name === 'h' && key.shift) {
|
|
147
|
+
self.move(self.childBase - self.selected);
|
|
148
|
+
self.screen.render();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (options.vi && key.name === 'm' && key.shift) {
|
|
152
|
+
// TODO: Maybe use Math.min(this.items.length,
|
|
153
|
+
// ... for calculating visible items elsewhere.
|
|
154
|
+
var visible = Math.min(
|
|
155
|
+
self.height - self.iheight,
|
|
156
|
+
self.items.length) / 2 | 0;
|
|
157
|
+
self.move(self.childBase + visible - self.selected);
|
|
158
|
+
self.screen.render();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (options.vi && key.name === 'l' && key.shift) {
|
|
162
|
+
// XXX This goes one too far on lists with an odd number of items.
|
|
163
|
+
self.down(self.childBase
|
|
164
|
+
+ Math.min(self.height - self.iheight, self.items.length)
|
|
165
|
+
- self.selected);
|
|
166
|
+
self.screen.render();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (options.vi && key.name === 'g' && !key.shift) {
|
|
170
|
+
self.select(0);
|
|
171
|
+
self.screen.render();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (options.vi && key.name === 'g' && key.shift) {
|
|
175
|
+
self.select(self.items.length - 1);
|
|
176
|
+
self.screen.render();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (options.vi && (key.ch === '/' || key.ch === '?')) {
|
|
181
|
+
if (typeof self.options.search !== 'function') {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
return self.options.search(function(err, value) {
|
|
185
|
+
if (typeof err === 'string' || typeof err === 'function'
|
|
186
|
+
|| typeof err === 'number' || (err && err.test)) {
|
|
187
|
+
value = err;
|
|
188
|
+
err = null;
|
|
189
|
+
}
|
|
190
|
+
if (err || !value) return self.screen.render();
|
|
191
|
+
self.select(self.fuzzyFind(value, key.ch === '?'));
|
|
192
|
+
self.screen.render();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.on('resize', function() {
|
|
199
|
+
var visible = self.height - self.iheight;
|
|
200
|
+
// if (self.selected < visible - 1) {
|
|
201
|
+
if (visible >= self.selected + 1) {
|
|
202
|
+
self.childBase = 0;
|
|
203
|
+
self.childOffset = self.selected;
|
|
204
|
+
} else {
|
|
205
|
+
// Is this supposed to be: self.childBase = visible - self.selected + 1; ?
|
|
206
|
+
self.childBase = self.selected - visible + 1;
|
|
207
|
+
self.childOffset = visible - 1;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
this.on('adopt', function(el) {
|
|
212
|
+
if (!~self.items.indexOf(el)) {
|
|
213
|
+
el.fixed = true;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Ensure children are removed from the
|
|
218
|
+
// item list if they are items.
|
|
219
|
+
this.on('remove', function(el) {
|
|
220
|
+
self.removeItem(el);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
List.prototype.__proto__ = Box.prototype;
|
|
225
|
+
|
|
226
|
+
List.prototype.type = 'list';
|
|
227
|
+
|
|
228
|
+
List.prototype.createItem = function(content) {
|
|
229
|
+
var self = this;
|
|
230
|
+
|
|
231
|
+
// Note: Could potentially use Button here.
|
|
232
|
+
var options = {
|
|
233
|
+
screen: this.screen,
|
|
234
|
+
content: content,
|
|
235
|
+
align: this.align || 'left',
|
|
236
|
+
top: 0,
|
|
237
|
+
left: 0,
|
|
238
|
+
right: (this.scrollbar ? 1 : 0),
|
|
239
|
+
tags: this.parseTags,
|
|
240
|
+
height: 1,
|
|
241
|
+
hoverEffects: this.mouse ? this.style.item.hover : null,
|
|
242
|
+
focusEffects: this.mouse ? this.style.item.focus : null,
|
|
243
|
+
autoFocus: false
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
if (!this.screen.autoPadding) {
|
|
247
|
+
options.top = 1;
|
|
248
|
+
options.left = this.ileft;
|
|
249
|
+
options.right = this.iright + (this.scrollbar ? 1 : 0);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// if (this.shrink) {
|
|
253
|
+
// XXX NOTE: Maybe just do this on all shrinkage once autoPadding is default?
|
|
254
|
+
if (this.shrink && this.options.normalShrink) {
|
|
255
|
+
delete options.right;
|
|
256
|
+
options.width = 'shrink';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
['bg', 'fg', 'bold', 'underline',
|
|
260
|
+
'blink', 'inverse', 'invisible'].forEach(function(name) {
|
|
261
|
+
options[name] = function() {
|
|
262
|
+
var attr = self.items[self.selected] === item && self.interactive
|
|
263
|
+
? self.style.selected[name]
|
|
264
|
+
: self.style.item[name];
|
|
265
|
+
if (typeof attr === 'function') attr = attr(item);
|
|
266
|
+
return attr;
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if (this.style.transparent) {
|
|
271
|
+
options.transparent = true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var item = new Box(options);
|
|
275
|
+
|
|
276
|
+
if (this.mouse) {
|
|
277
|
+
item.on('click', function() {
|
|
278
|
+
self.focus();
|
|
279
|
+
if (self.items[self.selected] === item) {
|
|
280
|
+
self.emit('action', item, self.selected);
|
|
281
|
+
self.emit('select', item, self.selected);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
self.select(item);
|
|
285
|
+
self.screen.render();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this.emit('create item');
|
|
290
|
+
|
|
291
|
+
return item;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
List.prototype.add =
|
|
295
|
+
List.prototype.addItem =
|
|
296
|
+
List.prototype.appendItem = function(content) {
|
|
297
|
+
content = typeof content === 'string' ? content : content.getContent();
|
|
298
|
+
|
|
299
|
+
var item = this.createItem(content);
|
|
300
|
+
item.position.top = this.items.length;
|
|
301
|
+
if (!this.screen.autoPadding) {
|
|
302
|
+
item.position.top = this.itop + this.items.length;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
this.ritems.push(content);
|
|
306
|
+
this.items.push(item);
|
|
307
|
+
this.append(item);
|
|
308
|
+
|
|
309
|
+
if (this.items.length === 1) {
|
|
310
|
+
this.select(0);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this.emit('add item');
|
|
314
|
+
|
|
315
|
+
return item;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
List.prototype.removeItem = function(child) {
|
|
319
|
+
var i = this.getItemIndex(child);
|
|
320
|
+
if (~i && this.items[i]) {
|
|
321
|
+
child = this.items.splice(i, 1)[0];
|
|
322
|
+
this.ritems.splice(i, 1);
|
|
323
|
+
this.remove(child);
|
|
324
|
+
for (var j = i; j < this.items.length; j++) {
|
|
325
|
+
this.items[j].position.top--;
|
|
326
|
+
}
|
|
327
|
+
if (i === this.selected) {
|
|
328
|
+
this.select(i - 1);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
this.emit('remove item');
|
|
332
|
+
return child;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
List.prototype.insertItem = function(child, content) {
|
|
336
|
+
content = typeof content === 'string' ? content : content.getContent();
|
|
337
|
+
var i = this.getItemIndex(child);
|
|
338
|
+
if (!~i) return;
|
|
339
|
+
if (i >= this.items.length) return this.appendItem(content);
|
|
340
|
+
var item = this.createItem(content);
|
|
341
|
+
for (var j = i; j < this.items.length; j++) {
|
|
342
|
+
this.items[j].position.top++;
|
|
343
|
+
}
|
|
344
|
+
item.position.top = i + (!this.screen.autoPadding ? 1 : 0);
|
|
345
|
+
this.ritems.splice(i, 0, content);
|
|
346
|
+
this.items.splice(i, 0, item);
|
|
347
|
+
this.append(item);
|
|
348
|
+
if (i === this.selected) {
|
|
349
|
+
this.select(i + 1);
|
|
350
|
+
}
|
|
351
|
+
this.emit('insert item');
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
List.prototype.getItem = function(child) {
|
|
355
|
+
return this.items[this.getItemIndex(child)];
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
List.prototype.setItem = function(child, content) {
|
|
359
|
+
content = typeof content === 'string' ? content : content.getContent();
|
|
360
|
+
var i = this.getItemIndex(child);
|
|
361
|
+
if (!~i) return;
|
|
362
|
+
this.items[i].setContent(content);
|
|
363
|
+
this.ritems[i] = content;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
List.prototype.clearItems = function() {
|
|
367
|
+
return this.setItems([]);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
List.prototype.setItems = function(items) {
|
|
371
|
+
var original = this.items.slice()
|
|
372
|
+
, selected = this.selected
|
|
373
|
+
, sel = this.ritems[this.selected]
|
|
374
|
+
, i = 0;
|
|
375
|
+
|
|
376
|
+
items = items.slice();
|
|
377
|
+
|
|
378
|
+
this.select(0);
|
|
379
|
+
|
|
380
|
+
for (; i < items.length; i++) {
|
|
381
|
+
if (this.items[i]) {
|
|
382
|
+
this.items[i].setContent(items[i]);
|
|
383
|
+
} else {
|
|
384
|
+
this.add(items[i]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
for (; i < original.length; i++) {
|
|
389
|
+
this.remove(original[i]);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
this.ritems = items;
|
|
393
|
+
|
|
394
|
+
// Try to find our old item if it still exists.
|
|
395
|
+
sel = items.indexOf(sel);
|
|
396
|
+
if (~sel) {
|
|
397
|
+
this.select(sel);
|
|
398
|
+
} else if (items.length === original.length) {
|
|
399
|
+
this.select(selected);
|
|
400
|
+
} else {
|
|
401
|
+
this.select(Math.min(selected, items.length - 1));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
this.emit('set items');
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
List.prototype.pushItem = function(content) {
|
|
408
|
+
this.appendItem(content);
|
|
409
|
+
return this.items.length;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
List.prototype.popItem = function() {
|
|
413
|
+
return this.removeItem(this.items.length - 1);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
List.prototype.unshiftItem = function(content) {
|
|
417
|
+
this.insertItem(0, content);
|
|
418
|
+
return this.items.length;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
List.prototype.shiftItem = function() {
|
|
422
|
+
return this.removeItem(0);
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
List.prototype.spliceItem = function(child, n) {
|
|
426
|
+
var self = this;
|
|
427
|
+
var i = this.getItemIndex(child);
|
|
428
|
+
if (!~i) return;
|
|
429
|
+
var items = Array.prototype.slice.call(arguments, 2);
|
|
430
|
+
var removed = [];
|
|
431
|
+
while (n--) {
|
|
432
|
+
removed.push(this.removeItem(i));
|
|
433
|
+
}
|
|
434
|
+
items.forEach(function(item) {
|
|
435
|
+
self.insertItem(i++, item);
|
|
436
|
+
});
|
|
437
|
+
return removed;
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
List.prototype.find =
|
|
441
|
+
List.prototype.fuzzyFind = function(search, back) {
|
|
442
|
+
var start = this.selected + (back ? -1 : 1)
|
|
443
|
+
, i;
|
|
444
|
+
|
|
445
|
+
if (typeof search === 'number') search += '';
|
|
446
|
+
|
|
447
|
+
if (search && search[0] === '/' && search[search.length - 1] === '/') {
|
|
448
|
+
try {
|
|
449
|
+
search = new RegExp(search.slice(1, -1));
|
|
450
|
+
} catch (e) {
|
|
451
|
+
;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
var test = typeof search === 'string'
|
|
456
|
+
? function(item) { return !!~item.indexOf(search); }
|
|
457
|
+
: (search.test ? search.test.bind(search) : search);
|
|
458
|
+
|
|
459
|
+
if (typeof test !== 'function') {
|
|
460
|
+
if (this.screen.options.debug) {
|
|
461
|
+
throw new Error('fuzzyFind(): `test` is not a function.');
|
|
462
|
+
}
|
|
463
|
+
return this.selected;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (!back) {
|
|
467
|
+
for (i = start; i < this.ritems.length; i++) {
|
|
468
|
+
if (test(helpers.cleanTags(this.ritems[i]))) return i;
|
|
469
|
+
}
|
|
470
|
+
for (i = 0; i < start; i++) {
|
|
471
|
+
if (test(helpers.cleanTags(this.ritems[i]))) return i;
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
for (i = start; i >= 0; i--) {
|
|
475
|
+
if (test(helpers.cleanTags(this.ritems[i]))) return i;
|
|
476
|
+
}
|
|
477
|
+
for (i = this.ritems.length - 1; i > start; i--) {
|
|
478
|
+
if (test(helpers.cleanTags(this.ritems[i]))) return i;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return this.selected;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
List.prototype.getItemIndex = function(child) {
|
|
486
|
+
if (typeof child === 'number') {
|
|
487
|
+
return child;
|
|
488
|
+
} else if (typeof child === 'string') {
|
|
489
|
+
var i = this.ritems.indexOf(child);
|
|
490
|
+
if (~i) return i;
|
|
491
|
+
for (i = 0; i < this.ritems.length; i++) {
|
|
492
|
+
if (helpers.cleanTags(this.ritems[i]) === child) {
|
|
493
|
+
return i;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return -1;
|
|
497
|
+
} else {
|
|
498
|
+
return this.items.indexOf(child);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
List.prototype.select = function(index) {
|
|
503
|
+
if (!this.interactive) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (!this.items.length) {
|
|
508
|
+
this.selected = 0;
|
|
509
|
+
this.value = '';
|
|
510
|
+
this.scrollTo(0);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (typeof index === 'object') {
|
|
515
|
+
index = this.items.indexOf(index);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (index < 0) {
|
|
519
|
+
index = 0;
|
|
520
|
+
} else if (index >= this.items.length) {
|
|
521
|
+
index = this.items.length - 1;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (this.selected === index && this._listInitialized) return;
|
|
525
|
+
this._listInitialized = true;
|
|
526
|
+
|
|
527
|
+
this.selected = index;
|
|
528
|
+
this.value = helpers.cleanTags(this.ritems[this.selected]);
|
|
529
|
+
if (!this.parent) return;
|
|
530
|
+
this.scrollTo(this.selected);
|
|
531
|
+
|
|
532
|
+
// XXX Move `action` and `select` events here.
|
|
533
|
+
this.emit('select item', this.items[this.selected], this.selected);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
List.prototype.move = function(offset) {
|
|
537
|
+
this.select(this.selected + offset);
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
List.prototype.up = function(offset) {
|
|
541
|
+
this.move(-(offset || 1));
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
List.prototype.down = function(offset) {
|
|
545
|
+
this.move(offset || 1);
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
List.prototype.pick = function(label, callback) {
|
|
549
|
+
if (!callback) {
|
|
550
|
+
callback = label;
|
|
551
|
+
label = null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (!this.interactive) {
|
|
555
|
+
return callback();
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var self = this;
|
|
559
|
+
var focused = this.screen.focused;
|
|
560
|
+
if (focused && focused._done) focused._done('stop');
|
|
561
|
+
this.screen.saveFocus();
|
|
562
|
+
|
|
563
|
+
// XXX Keep above:
|
|
564
|
+
// var parent = this.parent;
|
|
565
|
+
// this.detach();
|
|
566
|
+
// parent.append(this);
|
|
567
|
+
|
|
568
|
+
this.focus();
|
|
569
|
+
this.show();
|
|
570
|
+
this.select(0);
|
|
571
|
+
if (label) this.setLabel(label);
|
|
572
|
+
this.screen.render();
|
|
573
|
+
this.once('action', function(el, selected) {
|
|
574
|
+
if (label) self.removeLabel();
|
|
575
|
+
self.screen.restoreFocus();
|
|
576
|
+
self.hide();
|
|
577
|
+
self.screen.render();
|
|
578
|
+
if (!el) return callback();
|
|
579
|
+
return callback(null, helpers.cleanTags(self.ritems[selected]));
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
List.prototype.enterSelected = function(i) {
|
|
584
|
+
if (i != null) this.select(i);
|
|
585
|
+
this.emit('action', this.items[this.selected], this.selected);
|
|
586
|
+
this.emit('select', this.items[this.selected], this.selected);
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
List.prototype.cancelSelected = function(i) {
|
|
590
|
+
if (i != null) this.select(i);
|
|
591
|
+
this.emit('action');
|
|
592
|
+
this.emit('cancel');
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Expose
|
|
597
|
+
*/
|
|
598
|
+
|
|
599
|
+
module.exports = List;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* log.js - log element for blessed
|
|
3
|
+
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
|
|
4
|
+
* https://github.com/chjj/blessed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Modules
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var util = require('util');
|
|
12
|
+
|
|
13
|
+
var nextTick = global.setImmediate || process.nextTick.bind(process);
|
|
14
|
+
|
|
15
|
+
var Node = require('./node');
|
|
16
|
+
var ScrollableText = require('./scrollabletext');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Log
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function Log(options) {
|
|
23
|
+
var self = this;
|
|
24
|
+
|
|
25
|
+
if (!(this instanceof Node)) {
|
|
26
|
+
return new Log(options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
options = options || {};
|
|
30
|
+
|
|
31
|
+
ScrollableText.call(this, options);
|
|
32
|
+
|
|
33
|
+
this.scrollback = options.scrollback != null
|
|
34
|
+
? options.scrollback
|
|
35
|
+
: Infinity;
|
|
36
|
+
this.scrollOnInput = options.scrollOnInput;
|
|
37
|
+
|
|
38
|
+
this.on('set content', function() {
|
|
39
|
+
if (!self._userScrolled || self.scrollOnInput) {
|
|
40
|
+
nextTick(function() {
|
|
41
|
+
self.setScrollPerc(100);
|
|
42
|
+
self._userScrolled = false;
|
|
43
|
+
self.screen.render();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Log.prototype.__proto__ = ScrollableText.prototype;
|
|
50
|
+
|
|
51
|
+
Log.prototype.type = 'log';
|
|
52
|
+
|
|
53
|
+
Log.prototype.log =
|
|
54
|
+
Log.prototype.add = function() {
|
|
55
|
+
var args = Array.prototype.slice.call(arguments);
|
|
56
|
+
if (typeof args[0] === 'object') {
|
|
57
|
+
args[0] = util.inspect(args[0], true, 20, true);
|
|
58
|
+
}
|
|
59
|
+
var text = util.format.apply(util, args);
|
|
60
|
+
this.emit('log', text);
|
|
61
|
+
var ret = this.pushLine(text);
|
|
62
|
+
if (this._clines.fake.length > this.scrollback) {
|
|
63
|
+
this.shiftLine(0, (this.scrollback / 3) | 0);
|
|
64
|
+
}
|
|
65
|
+
return ret;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
Log.prototype._scroll = Log.prototype.scroll;
|
|
69
|
+
Log.prototype.scroll = function(offset, always) {
|
|
70
|
+
if (offset === 0) return this._scroll(offset, always);
|
|
71
|
+
this._userScrolled = true;
|
|
72
|
+
var ret = this._scroll(offset, always);
|
|
73
|
+
if (this.getScrollPerc() === 100) {
|
|
74
|
+
this._userScrolled = false;
|
|
75
|
+
}
|
|
76
|
+
return ret;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Expose
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
module.exports = Log;
|