@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.
Files changed (267) hide show
  1. package/CHANGELOG.md +2607 -0
  2. package/CONTRIBUTING.md +124 -0
  3. package/GNU-AGPL-3.0.txt +665 -0
  4. package/LICENSE +1 -0
  5. package/README.md +255 -2
  6. package/SECURITY.md +41 -0
  7. package/bin/pm2 +3 -0
  8. package/bin/pm2-dev +3 -0
  9. package/bin/pm2-docker +3 -0
  10. package/bin/pm2-runtime +3 -0
  11. package/bin/pm2.ps1 +3 -0
  12. package/constants.js +113 -0
  13. package/index.js +12 -0
  14. package/lib/API/Configuration.js +212 -0
  15. package/lib/API/Containerizer.js +335 -0
  16. package/lib/API/Dashboard.js +726 -0
  17. package/lib/API/Deploy.js +117 -0
  18. package/lib/API/Extra.js +798 -0
  19. package/lib/API/ExtraMgmt/Docker.js +30 -0
  20. package/lib/API/Log.js +388 -0
  21. package/lib/API/LogManagement.js +351 -0
  22. package/lib/API/Modules/LOCAL.js +122 -0
  23. package/lib/API/Modules/Modularizer.js +148 -0
  24. package/lib/API/Modules/NPM.js +443 -0
  25. package/lib/API/Modules/TAR.js +368 -0
  26. package/lib/API/Modules/flagExt.js +46 -0
  27. package/lib/API/Modules/index.js +120 -0
  28. package/lib/API/Monit.js +247 -0
  29. package/lib/API/Serve.js +497 -0
  30. package/lib/API/Startup.js +630 -0
  31. package/lib/API/UX/helpers.js +213 -0
  32. package/lib/API/UX/index.js +9 -0
  33. package/lib/API/UX/pm2-describe.js +197 -0
  34. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  35. package/lib/API/UX/pm2-ls.js +581 -0
  36. package/lib/API/Version.js +383 -0
  37. package/lib/API/interpreter.json +12 -0
  38. package/lib/API/pm2-plus/PM2IO.js +381 -0
  39. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
  40. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
  41. package/lib/API/pm2-plus/helpers.js +97 -0
  42. package/lib/API/pm2-plus/link.js +126 -0
  43. package/lib/API/pm2-plus/pres/motd +16 -0
  44. package/lib/API/pm2-plus/pres/motd.update +26 -0
  45. package/lib/API/pm2-plus/pres/welcome +28 -0
  46. package/lib/API/pm2-plus/process-selector.js +52 -0
  47. package/lib/API/schema.json +375 -0
  48. package/lib/API.js +1980 -0
  49. package/lib/Client.js +793 -0
  50. package/lib/Common.js +949 -0
  51. package/lib/Configuration.js +309 -0
  52. package/lib/Daemon.js +468 -0
  53. package/lib/Event.js +37 -0
  54. package/lib/God/ActionMethods.js +955 -0
  55. package/lib/God/ClusterMode.js +192 -0
  56. package/lib/God/ForkMode.js +205 -0
  57. package/lib/God/Methods.js +292 -0
  58. package/lib/God/Reload.js +300 -0
  59. package/lib/God/StdioLogger.js +239 -0
  60. package/lib/God.js +653 -0
  61. package/lib/HttpInterface.js +75 -0
  62. package/lib/OtelManager.js +74 -0
  63. package/lib/ProcessContainer.js +321 -0
  64. package/lib/ProcessContainerBun.js +355 -0
  65. package/lib/ProcessContainerFork.js +42 -0
  66. package/lib/ProcessContainerForkBun.js +31 -0
  67. package/lib/ProcessUtils.js +74 -0
  68. package/lib/TreeKill.js +111 -0
  69. package/lib/Utility.js +304 -0
  70. package/lib/VersionCheck.js +46 -0
  71. package/lib/Watcher.js +117 -0
  72. package/lib/Worker.js +200 -0
  73. package/lib/binaries/CLI.js +1092 -0
  74. package/lib/binaries/DevCLI.js +183 -0
  75. package/lib/binaries/Runtime.js +101 -0
  76. package/lib/binaries/Runtime4Docker.js +192 -0
  77. package/lib/completion.js +229 -0
  78. package/lib/completion.sh +40 -0
  79. package/lib/motd +36 -0
  80. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  81. package/lib/templates/ecosystem-es.tpl +24 -0
  82. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  83. package/lib/templates/ecosystem-simple.tpl +6 -0
  84. package/lib/templates/ecosystem.tpl +22 -0
  85. package/lib/templates/init-scripts/launchd.tpl +35 -0
  86. package/lib/templates/init-scripts/openrc.tpl +52 -0
  87. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  88. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  89. package/lib/templates/init-scripts/rcd.tpl +44 -0
  90. package/lib/templates/init-scripts/smf.tpl +43 -0
  91. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  92. package/lib/templates/init-scripts/systemd.tpl +22 -0
  93. package/lib/templates/init-scripts/upstart.tpl +103 -0
  94. package/lib/templates/logrotate.d/pm2 +10 -0
  95. package/lib/templates/sample-apps/http-server/README.md +14 -0
  96. package/lib/templates/sample-apps/http-server/api.js +9 -0
  97. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  98. package/lib/templates/sample-apps/http-server/package.json +11 -0
  99. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  100. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  101. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  102. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  103. package/lib/templates/sample-apps/python-app/README.md +4 -0
  104. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  105. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  106. package/lib/templates/sample-apps/python-app/package.json +11 -0
  107. package/lib/tools/Config.js +251 -0
  108. package/lib/tools/SysMetrics.js +375 -0
  109. package/lib/tools/copydirSync.js +101 -0
  110. package/lib/tools/deleteFolderRecursive.js +19 -0
  111. package/lib/tools/find-package-json.js +74 -0
  112. package/lib/tools/fmt.js +72 -0
  113. package/lib/tools/interpreter.js +88 -0
  114. package/lib/tools/isbinaryfile.js +94 -0
  115. package/lib/tools/json5.js +752 -0
  116. package/lib/tools/multimeter/bar.js +111 -0
  117. package/lib/tools/multimeter/charm/encode.js +18 -0
  118. package/lib/tools/multimeter/charm/index.js +305 -0
  119. package/lib/tools/multimeter/index.js +76 -0
  120. package/lib/tools/open.js +56 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/pm2-config-keys.js +165 -0
  123. package/lib/tools/prompt.js +76 -0
  124. package/lib/tools/serviceStop.js +149 -0
  125. package/lib/tools/sexec.js +55 -0
  126. package/lib/tools/treeify.js +113 -0
  127. package/lib/tools/typestrip.js +55 -0
  128. package/lib/tools/which.js +120 -0
  129. package/lib/tools/xdg-open +861 -0
  130. package/modules/blessed/LICENSE +20 -0
  131. package/modules/blessed/README.md +34 -0
  132. package/modules/blessed/index.js +1 -0
  133. package/modules/blessed/lib/alias.js +526 -0
  134. package/modules/blessed/lib/blessed.js +32 -0
  135. package/modules/blessed/lib/colors.js +530 -0
  136. package/modules/blessed/lib/events.js +189 -0
  137. package/modules/blessed/lib/gpmclient.js +221 -0
  138. package/modules/blessed/lib/helpers.js +165 -0
  139. package/modules/blessed/lib/keys.js +339 -0
  140. package/modules/blessed/lib/program.js +4297 -0
  141. package/modules/blessed/lib/tput.js +3022 -0
  142. package/modules/blessed/lib/unicode.js +885 -0
  143. package/modules/blessed/lib/widget.js +32 -0
  144. package/modules/blessed/lib/widgets/box.js +34 -0
  145. package/modules/blessed/lib/widgets/element.js +2570 -0
  146. package/modules/blessed/lib/widgets/list.js +599 -0
  147. package/modules/blessed/lib/widgets/log.js +83 -0
  148. package/modules/blessed/lib/widgets/node.js +282 -0
  149. package/modules/blessed/lib/widgets/screen.js +2298 -0
  150. package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
  151. package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
  152. package/modules/blessed/lib/widgets/text.js +35 -0
  153. package/modules/blessed/usr/linux +0 -0
  154. package/modules/blessed/usr/windows-ansi +0 -0
  155. package/modules/blessed/usr/xterm +0 -0
  156. package/modules/blessed/usr/xterm-256color +0 -0
  157. package/modules/blessed/usr/xterm.termcap +243 -0
  158. package/modules/chokidar/LICENSE +21 -0
  159. package/modules/chokidar/VENDORED.md +76 -0
  160. package/modules/chokidar/index.js +979 -0
  161. package/modules/chokidar/lib/brace-expand.js +180 -0
  162. package/modules/chokidar/lib/constants.js +66 -0
  163. package/modules/chokidar/lib/fsevents-handler.js +526 -0
  164. package/modules/chokidar/lib/nodefs-handler.js +654 -0
  165. package/modules/fclone.js +49 -0
  166. package/modules/pm2-axon/index.js +2 -0
  167. package/modules/pm2-axon/lib/configurable/History.md +5 -0
  168. package/modules/pm2-axon/lib/configurable/Makefile +7 -0
  169. package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
  170. package/modules/pm2-axon/lib/configurable/index.js +2 -0
  171. package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
  172. package/modules/pm2-axon/lib/configurable/package.json +68 -0
  173. package/modules/pm2-axon/lib/index.js +44 -0
  174. package/modules/pm2-axon/lib/plugins/queue.js +71 -0
  175. package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
  176. package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
  177. package/modules/pm2-axon/lib/sockets/pub.js +77 -0
  178. package/modules/pm2-axon/lib/sockets/pull.js +37 -0
  179. package/modules/pm2-axon/lib/sockets/push.js +32 -0
  180. package/modules/pm2-axon/lib/sockets/rep.js +73 -0
  181. package/modules/pm2-axon/lib/sockets/req.js +101 -0
  182. package/modules/pm2-axon/lib/sockets/sock.js +430 -0
  183. package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
  184. package/modules/pm2-axon/lib/sockets/sub.js +147 -0
  185. package/modules/pm2-axon/lib/utils.js +19 -0
  186. package/modules/pm2-axon-rpc/index.js +3 -0
  187. package/modules/pm2-axon-rpc/lib/client.js +63 -0
  188. package/modules/pm2-axon-rpc/lib/server.js +139 -0
  189. package/modules/pm2-io-agent/LICENSE +661 -0
  190. package/modules/pm2-io-agent/README.md +62 -0
  191. package/modules/pm2-io-agent/config.js +30 -0
  192. package/modules/pm2-io-agent/constants.js +118 -0
  193. package/modules/pm2-io-agent/index.js +2 -0
  194. package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
  195. package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
  196. package/modules/pm2-io-agent/src/PM2Client.js +112 -0
  197. package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
  198. package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
  199. package/modules/pm2-io-agent/src/Utility.js +392 -0
  200. package/modules/pm2-io-agent/src/WatchDog.js +70 -0
  201. package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
  202. package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
  203. package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
  204. package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
  205. package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
  206. package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
  207. package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
  208. package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
  209. package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
  210. package/modules/pm2-io-agent/src/utils/units.js +10 -0
  211. package/modules/pm2-io-bpm/configuration.js +141 -0
  212. package/modules/pm2-io-bpm/constants.js +10 -0
  213. package/modules/pm2-io-bpm/featureManager.js +110 -0
  214. package/modules/pm2-io-bpm/features/dependencies.js +48 -0
  215. package/modules/pm2-io-bpm/features/events.js +50 -0
  216. package/modules/pm2-io-bpm/features/metrics.js +102 -0
  217. package/modules/pm2-io-bpm/features/notify.js +238 -0
  218. package/modules/pm2-io-bpm/features/profiling.js +70 -0
  219. package/modules/pm2-io-bpm/features/tracing.js +174 -0
  220. package/modules/pm2-io-bpm/index.js +11 -0
  221. package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
  222. package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
  223. package/modules/pm2-io-bpm/metrics/network.js +132 -0
  224. package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
  225. package/modules/pm2-io-bpm/metrics/v8.js +104 -0
  226. package/modules/pm2-io-bpm/otel/constants.js +7 -0
  227. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
  228. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
  229. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
  230. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
  231. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
  232. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
  233. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
  234. package/modules/pm2-io-bpm/pmx.js +380 -0
  235. package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
  236. package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
  237. package/modules/pm2-io-bpm/serviceManager.js +21 -0
  238. package/modules/pm2-io-bpm/services/actions.js +159 -0
  239. package/modules/pm2-io-bpm/services/inspector.js +43 -0
  240. package/modules/pm2-io-bpm/services/metrics.js +186 -0
  241. package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
  242. package/modules/pm2-io-bpm/services/transport.js +11 -0
  243. package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
  244. package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
  245. package/modules/pm2-io-bpm/utils/EDS.js +113 -0
  246. package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
  247. package/modules/pm2-io-bpm/utils/autocast.js +61 -0
  248. package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
  249. package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
  250. package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
  251. package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
  252. package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
  253. package/modules/pm2-io-bpm/utils/module.js +67 -0
  254. package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
  255. package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
  256. package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
  257. package/modules/pm2-io-bpm/utils/units.js +16 -0
  258. package/modules/vizion/LICENSE +13 -0
  259. package/modules/vizion/README.md +133 -0
  260. package/modules/vizion/index.js +1 -0
  261. package/modules/vizion/lib/git/git.js +247 -0
  262. package/modules/vizion/lib/vizion.js +52 -0
  263. package/package.json +170 -4
  264. package/paths.js +121 -0
  265. package/pm2 +11 -0
  266. package/types/index.d.ts +732 -0
  267. package/types/tsconfig.json +14 -0
@@ -0,0 +1,189 @@
1
+ /**
2
+ * events.js - event emitter for blessed
3
+ * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
4
+ * https://github.com/chjj/blessed
5
+ */
6
+
7
+ var slice = Array.prototype.slice;
8
+
9
+ /**
10
+ * EventEmitter
11
+ */
12
+
13
+ function EventEmitter() {
14
+ if (!this._events) this._events = {};
15
+ }
16
+
17
+ EventEmitter.prototype.setMaxListeners = function(n) {
18
+ this._maxListeners = n;
19
+ };
20
+
21
+ EventEmitter.prototype.addListener = function(type, listener) {
22
+ if (!this._events[type]) {
23
+ this._events[type] = listener;
24
+ } else if (typeof this._events[type] === 'function') {
25
+ this._events[type] = [this._events[type], listener];
26
+ } else {
27
+ this._events[type].push(listener);
28
+ }
29
+ this._emit('newListener', [type, listener]);
30
+ };
31
+
32
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
33
+
34
+ EventEmitter.prototype.removeListener = function(type, listener) {
35
+ var handler = this._events[type];
36
+ if (!handler) return;
37
+
38
+ if (typeof handler === 'function' || handler.length === 1) {
39
+ delete this._events[type];
40
+ this._emit('removeListener', [type, listener]);
41
+ return;
42
+ }
43
+
44
+ for (var i = 0; i < handler.length; i++) {
45
+ if (handler[i] === listener || handler[i].listener === listener) {
46
+ handler.splice(i, 1);
47
+ this._emit('removeListener', [type, listener]);
48
+ return;
49
+ }
50
+ }
51
+ };
52
+
53
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
54
+
55
+ EventEmitter.prototype.removeAllListeners = function(type) {
56
+ if (type) {
57
+ delete this._events[type];
58
+ } else {
59
+ this._events = {};
60
+ }
61
+ };
62
+
63
+ EventEmitter.prototype.once = function(type, listener) {
64
+ function on() {
65
+ this.removeListener(type, on);
66
+ return listener.apply(this, arguments);
67
+ }
68
+ on.listener = listener;
69
+ return this.on(type, on);
70
+ };
71
+
72
+ EventEmitter.prototype.listeners = function(type) {
73
+ return typeof this._events[type] === 'function'
74
+ ? [this._events[type]]
75
+ : this._events[type] || [];
76
+ };
77
+
78
+ EventEmitter.prototype._emit = function(type, args) {
79
+ var handler = this._events[type]
80
+ , ret;
81
+
82
+ // if (type !== 'event') {
83
+ // this._emit('event', [type.replace(/^element /, '')].concat(args));
84
+ // }
85
+
86
+ if (!handler) {
87
+ if (type === 'error') {
88
+ throw new args[0];
89
+ }
90
+ return;
91
+ }
92
+
93
+ if (typeof handler === 'function') {
94
+ return handler.apply(this, args);
95
+ }
96
+
97
+ for (var i = 0; i < handler.length; i++) {
98
+ if (handler[i].apply(this, args) === false) {
99
+ ret = false;
100
+ }
101
+ }
102
+
103
+ return ret !== false;
104
+ };
105
+
106
+ EventEmitter.prototype.emit = function(type) {
107
+ var args = slice.call(arguments, 1)
108
+ , params = slice.call(arguments)
109
+ , el = this;
110
+
111
+ this._emit('event', params);
112
+
113
+ if (this.type === 'screen') {
114
+ return this._emit(type, args);
115
+ }
116
+
117
+ if (this._emit(type, args) === false) {
118
+ return false;
119
+ }
120
+
121
+ type = 'element ' + type;
122
+ args.unshift(this);
123
+ // `element` prefix
124
+ // params = [type].concat(args);
125
+ // no `element` prefix
126
+ // params.splice(1, 0, this);
127
+
128
+ do {
129
+ // el._emit('event', params);
130
+ if (!el._events[type]) continue;
131
+ if (el._emit(type, args) === false) {
132
+ return false;
133
+ }
134
+ } while (el = el.parent);
135
+
136
+ return true;
137
+ };
138
+
139
+ // For hooking into the main EventEmitter if we want to.
140
+ // Might be better to do things this way being that it
141
+ // will always be compatible with node, not to mention
142
+ // it gives us domain support as well.
143
+ // Node.prototype._emit = Node.prototype.emit;
144
+ // Node.prototype.emit = function(type) {
145
+ // var args, el;
146
+ //
147
+ // if (this.type === 'screen') {
148
+ // return this._emit.apply(this, arguments);
149
+ // }
150
+ //
151
+ // this._emit.apply(this, arguments);
152
+ // if (this._bubbleStopped) return false;
153
+ //
154
+ // args = slice.call(arguments, 1);
155
+ // el = this;
156
+ //
157
+ // args.unshift('element ' + type, this);
158
+ // this._bubbleStopped = false;
159
+ // //args.push(stopBubble);
160
+ //
161
+ // do {
162
+ // if (!el._events || !el._events[type]) continue;
163
+ // el._emit.apply(el, args);
164
+ // if (this._bubbleStopped) return false;
165
+ // } while (el = el.parent);
166
+ //
167
+ // return true;
168
+ // };
169
+ //
170
+ // Node.prototype._addListener = Node.prototype.addListener;
171
+ // Node.prototype.on =
172
+ // Node.prototype.addListener = function(type, listener) {
173
+ // function on() {
174
+ // if (listener.apply(this, arguments) === false) {
175
+ // this._bubbleStopped = true;
176
+ // }
177
+ // }
178
+ // on.listener = listener;
179
+ // return this._addListener(type, on);
180
+ // };
181
+
182
+ /**
183
+ * Expose
184
+ */
185
+
186
+ exports = EventEmitter;
187
+ exports.EventEmitter = EventEmitter;
188
+
189
+ module.exports = exports;
@@ -0,0 +1,221 @@
1
+ /**
2
+ * gpmclient.js - support the gpm mouse protocol
3
+ * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
4
+ * https://github.com/chjj/blessed
5
+ */
6
+
7
+ var net = require('net');
8
+ var fs = require('fs');
9
+ var EventEmitter = require('events').EventEmitter;
10
+
11
+ var GPM_USE_MAGIC = false;
12
+
13
+ var GPM_MOVE = 1
14
+ , GPM_DRAG = 2
15
+ , GPM_DOWN = 4
16
+ , GPM_UP = 8;
17
+
18
+ var GPM_DOUBLE = 32
19
+ , GPM_MFLAG = 128;
20
+
21
+ var GPM_REQ_NOPASTE = 3
22
+ , GPM_HARD = 256;
23
+
24
+ var GPM_MAGIC = 0x47706D4C;
25
+ var GPM_SOCKET = '/dev/gpmctl';
26
+
27
+ // typedef struct Gpm_Connect {
28
+ // unsigned short eventMask, defaultMask;
29
+ // unsigned short minMod, maxMod;
30
+ // int pid;
31
+ // int vc;
32
+ // } Gpm_Connect;
33
+
34
+ function send_config(socket, Gpm_Connect, callback) {
35
+ var buffer;
36
+ if (GPM_USE_MAGIC) {
37
+ buffer = new Buffer(20);
38
+ buffer.writeUInt32LE(GPM_MAGIC, 0);
39
+ buffer.writeUInt16LE(Gpm_Connect.eventMask, 4);
40
+ buffer.writeUInt16LE(Gpm_Connect.defaultMask, 6);
41
+ buffer.writeUInt16LE(Gpm_Connect.minMod, 8);
42
+ buffer.writeUInt16LE(Gpm_Connect.maxMod, 10);
43
+ buffer.writeInt16LE(process.pid, 12);
44
+ buffer.writeInt16LE(Gpm_Connect.vc, 16);
45
+ } else {
46
+ buffer = new Buffer(16);
47
+ buffer.writeUInt16LE(Gpm_Connect.eventMask, 0);
48
+ buffer.writeUInt16LE(Gpm_Connect.defaultMask, 2);
49
+ buffer.writeUInt16LE(Gpm_Connect.minMod, 4);
50
+ buffer.writeUInt16LE(Gpm_Connect.maxMod, 6);
51
+ buffer.writeInt16LE(Gpm_Connect.pid, 8);
52
+ buffer.writeInt16LE(Gpm_Connect.vc, 12);
53
+ }
54
+ socket.write(buffer, function() {
55
+ if (callback) callback();
56
+ });
57
+ }
58
+
59
+ // typedef struct Gpm_Event {
60
+ // unsigned char buttons, modifiers; // try to be a multiple of 4
61
+ // unsigned short vc;
62
+ // short dx, dy, x, y; // displacement x,y for this event, and absolute x,y
63
+ // enum Gpm_Etype type;
64
+ // // clicks e.g. double click are determined by time-based processing
65
+ // int clicks;
66
+ // enum Gpm_Margin margin;
67
+ // // wdx/y: displacement of wheels in this event. Absolute values are not
68
+ // // required, because wheel movement is typically used for scrolling
69
+ // // or selecting fields, not for cursor positioning. The application
70
+ // // can determine when the end of file or form is reached, and not
71
+ // // go any further.
72
+ // // A single mouse will use wdy, "vertical scroll" wheel.
73
+ // short wdx, wdy;
74
+ // } Gpm_Event;
75
+
76
+ function parseEvent(raw) {
77
+ var evnt = {};
78
+ evnt.buttons = raw[0];
79
+ evnt.modifiers = raw[1];
80
+ evnt.vc = raw.readUInt16LE(2);
81
+ evnt.dx = raw.readInt16LE(4);
82
+ evnt.dy = raw.readInt16LE(6);
83
+ evnt.x = raw.readInt16LE(8);
84
+ evnt.y = raw.readInt16LE(10);
85
+ evnt.type = raw.readInt16LE(12);
86
+ evnt.clicks = raw.readInt32LE(16);
87
+ evnt.margin = raw.readInt32LE(20);
88
+ evnt.wdx = raw.readInt16LE(24);
89
+ evnt.wdy = raw.readInt16LE(26);
90
+ return evnt;
91
+ }
92
+
93
+ function GpmClient(options) {
94
+ if (!(this instanceof GpmClient)) {
95
+ return new GpmClient(options);
96
+ }
97
+
98
+ EventEmitter.call(this);
99
+
100
+ var pid = process.pid;
101
+
102
+ // check tty for /dev/tty[n]
103
+ var path;
104
+ try {
105
+ path = fs.readlinkSync('/proc/' + pid + '/fd/0');
106
+ } catch (e) {
107
+ ;
108
+ }
109
+ var tty = /tty[0-9]+$/.exec(path);
110
+ if (tty === null) {
111
+ // TODO: should also check for /dev/input/..
112
+ }
113
+
114
+ var vc;
115
+ if (tty) {
116
+ tty = tty[0];
117
+ vc = +/[0-9]+$/.exec(tty)[0];
118
+ }
119
+
120
+ var self = this;
121
+
122
+ if (tty) {
123
+ fs.stat(GPM_SOCKET, function(err, stat) {
124
+ if (err || !stat.isSocket()) {
125
+ return;
126
+ }
127
+
128
+ var conf = {
129
+ eventMask: 0xffff,
130
+ defaultMask: GPM_MOVE | GPM_HARD,
131
+ minMod: 0,
132
+ maxMod: 0xffff,
133
+ pid: pid,
134
+ vc: vc
135
+ };
136
+
137
+ var gpm = net.createConnection(GPM_SOCKET);
138
+ this.gpm = gpm;
139
+
140
+ gpm.on('connect', function() {
141
+ send_config(gpm, conf, function() {
142
+ conf.pid = 0;
143
+ conf.vc = GPM_REQ_NOPASTE;
144
+ //send_config(gpm, conf);
145
+ });
146
+ });
147
+
148
+ gpm.on('data', function(packet) {
149
+ var evnt = parseEvent(packet);
150
+ switch (evnt.type & 15) {
151
+ case GPM_MOVE:
152
+ if (evnt.dx || evnt.dy) {
153
+ self.emit('move', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
154
+ }
155
+ if (evnt.wdx || evnt.wdy) {
156
+ self.emit('mousewheel',
157
+ evnt.buttons, evnt.modifiers,
158
+ evnt.x, evnt.y, evnt.wdx, evnt.wdy);
159
+ }
160
+ break;
161
+ case GPM_DRAG:
162
+ if (evnt.dx || evnt.dy) {
163
+ self.emit('drag', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
164
+ }
165
+ if (evnt.wdx || evnt.wdy) {
166
+ self.emit('mousewheel',
167
+ evnt.buttons, evnt.modifiers,
168
+ evnt.x, evnt.y, evnt.wdx, evnt.wdy);
169
+ }
170
+ break;
171
+ case GPM_DOWN:
172
+ self.emit('btndown', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
173
+ if (evnt.type & GPM_DOUBLE) {
174
+ self.emit('dblclick', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
175
+ }
176
+ break;
177
+ case GPM_UP:
178
+ self.emit('btnup', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
179
+ if (!(evnt.type & GPM_MFLAG)) {
180
+ self.emit('click', evnt.buttons, evnt.modifiers, evnt.x, evnt.y);
181
+ }
182
+ break;
183
+ }
184
+ });
185
+
186
+ gpm.on('error', function() {
187
+ self.stop();
188
+ });
189
+ });
190
+ }
191
+ }
192
+
193
+ GpmClient.prototype.__proto__ = EventEmitter.prototype;
194
+
195
+ GpmClient.prototype.stop = function() {
196
+ if (this.gpm) {
197
+ this.gpm.end();
198
+ }
199
+ delete this.gpm;
200
+ };
201
+
202
+ GpmClient.prototype.ButtonName = function(btn) {
203
+ if (btn & 4) return 'left';
204
+ if (btn & 2) return 'middle';
205
+ if (btn & 1) return 'right';
206
+ return '';
207
+ };
208
+
209
+ GpmClient.prototype.hasShiftKey = function(mod) {
210
+ return (mod & 1) ? true : false;
211
+ };
212
+
213
+ GpmClient.prototype.hasCtrlKey = function(mod) {
214
+ return (mod & 4) ? true : false;
215
+ };
216
+
217
+ GpmClient.prototype.hasMetaKey = function(mod) {
218
+ return (mod & 8) ? true : false;
219
+ };
220
+
221
+ module.exports = GpmClient;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * helpers.js - helpers 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 fs = require('fs');
12
+
13
+ var unicode = require('./unicode');
14
+
15
+ /**
16
+ * Helpers
17
+ */
18
+
19
+ var helpers = exports;
20
+
21
+ helpers.merge = function(a, b) {
22
+ Object.keys(b).forEach(function(key) {
23
+ a[key] = b[key];
24
+ });
25
+ return a;
26
+ };
27
+
28
+ helpers.asort = function(obj) {
29
+ return obj.sort(function(a, b) {
30
+ a = a.name.toLowerCase();
31
+ b = b.name.toLowerCase();
32
+
33
+ if (a[0] === '.' && b[0] === '.') {
34
+ a = a[1];
35
+ b = b[1];
36
+ } else {
37
+ a = a[0];
38
+ b = b[0];
39
+ }
40
+
41
+ return a > b ? 1 : (a < b ? -1 : 0);
42
+ });
43
+ };
44
+
45
+ helpers.hsort = function(obj) {
46
+ return obj.sort(function(a, b) {
47
+ return b.index - a.index;
48
+ });
49
+ };
50
+
51
+ helpers.findFile = function(start, target) {
52
+ return (function read(dir) {
53
+ var files, file, stat, out;
54
+
55
+ if (dir === '/dev' || dir === '/sys'
56
+ || dir === '/proc' || dir === '/net') {
57
+ return null;
58
+ }
59
+
60
+ try {
61
+ files = fs.readdirSync(dir);
62
+ } catch (e) {
63
+ files = [];
64
+ }
65
+
66
+ for (var i = 0; i < files.length; i++) {
67
+ file = files[i];
68
+
69
+ if (file === target) {
70
+ return (dir === '/' ? '' : dir) + '/' + file;
71
+ }
72
+
73
+ try {
74
+ stat = fs.lstatSync((dir === '/' ? '' : dir) + '/' + file);
75
+ } catch (e) {
76
+ stat = null;
77
+ }
78
+
79
+ if (stat && stat.isDirectory() && !stat.isSymbolicLink()) {
80
+ out = read((dir === '/' ? '' : dir) + '/' + file);
81
+ if (out) return out;
82
+ }
83
+ }
84
+
85
+ return null;
86
+ })(start);
87
+ };
88
+
89
+ // Escape text for tag-enabled elements.
90
+ helpers.escape = function(text) {
91
+ return text.replace(/[{}]/g, function(ch) {
92
+ return ch === '{' ? '{open}' : '{close}';
93
+ });
94
+ };
95
+
96
+ helpers.parseTags = function(text, screen) {
97
+ return helpers.Element.prototype._parseTags.call(
98
+ { parseTags: true, screen: screen || helpers.Screen.global }, text);
99
+ };
100
+
101
+ helpers.generateTags = function(style, text) {
102
+ var open = ''
103
+ , close = '';
104
+
105
+ Object.keys(style || {}).forEach(function(key) {
106
+ var val = style[key];
107
+ if (typeof val === 'string') {
108
+ val = val.replace(/^light(?!-)/, 'light-');
109
+ val = val.replace(/^bright(?!-)/, 'bright-');
110
+ open = '{' + val + '-' + key + '}' + open;
111
+ close += '{/' + val + '-' + key + '}';
112
+ } else {
113
+ if (val === true) {
114
+ open = '{' + key + '}' + open;
115
+ close += '{/' + key + '}';
116
+ }
117
+ }
118
+ });
119
+
120
+ if (text != null) {
121
+ return open + text + close;
122
+ }
123
+
124
+ return {
125
+ open: open,
126
+ close: close
127
+ };
128
+ };
129
+
130
+ helpers.attrToBinary = function(style, element) {
131
+ return helpers.Element.prototype.sattr.call(element || {}, style);
132
+ };
133
+
134
+ helpers.stripTags = function(text) {
135
+ if (!text) return '';
136
+ return text
137
+ .replace(/{(\/?)([\w\-,;!#]*)}/g, '')
138
+ .replace(/\x1b\[[\d;]*m/g, '');
139
+ };
140
+
141
+ helpers.cleanTags = function(text) {
142
+ return helpers.stripTags(text).trim();
143
+ };
144
+
145
+ helpers.dropUnicode = function(text) {
146
+ if (!text) return '';
147
+ return text
148
+ .replace(unicode.chars.all, '??')
149
+ .replace(unicode.chars.combining, '')
150
+ .replace(unicode.chars.surrogate, '?');
151
+ };
152
+
153
+ helpers.__defineGetter__('Screen', function() {
154
+ if (!helpers._screen) {
155
+ helpers._screen = require('./widgets/screen');
156
+ }
157
+ return helpers._screen;
158
+ });
159
+
160
+ helpers.__defineGetter__('Element', function() {
161
+ if (!helpers._element) {
162
+ helpers._element = require('./widgets/element');
163
+ }
164
+ return helpers._element;
165
+ });