spawn-term 1.0.7 → 1.0.8
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/dist/cjs/components/App.d.cts +3 -1
- package/dist/cjs/components/App.d.ts +3 -1
- package/dist/cjs/components/App.js +3 -4
- package/dist/cjs/components/App.js.map +1 -1
- package/dist/cjs/createApp.d.cts +1 -1
- package/dist/cjs/createApp.d.ts +1 -1
- package/dist/cjs/createApp.js +16 -9
- package/dist/cjs/createApp.js.map +1 -1
- package/dist/cjs/state/ProcessStore.d.cts +7 -4
- package/dist/cjs/state/ProcessStore.d.ts +7 -4
- package/dist/cjs/state/ProcessStore.js +11 -66
- package/dist/cjs/state/ProcessStore.js.map +1 -1
- package/dist/esm/components/App.d.ts +3 -1
- package/dist/esm/components/App.js +2 -4
- package/dist/esm/components/App.js.map +1 -1
- package/dist/esm/createApp.d.ts +1 -1
- package/dist/esm/createApp.js +17 -10
- package/dist/esm/createApp.js.map +1 -1
- package/dist/esm/state/ProcessStore.d.ts +7 -4
- package/dist/esm/state/ProcessStore.js +10 -8
- package/dist/esm/state/ProcessStore.js.map +1 -1
- package/package.json +2 -1
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
var _ink = require("ink");
|
|
13
|
-
var _ProcessContext = require("../state/ProcessContext.js");
|
|
14
13
|
var _ChildProcess = /*#__PURE__*/ _interop_require_default(require("./ChildProcess.js"));
|
|
15
14
|
function _define_property(obj, key, value) {
|
|
16
15
|
if (key in obj) {
|
|
@@ -45,11 +44,11 @@ function _object_spread(target) {
|
|
|
45
44
|
}
|
|
46
45
|
return target;
|
|
47
46
|
}
|
|
48
|
-
function App() {
|
|
49
|
-
var
|
|
47
|
+
function App(param) {
|
|
48
|
+
var store = param.store;
|
|
50
49
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ink.Box, {
|
|
51
50
|
flexDirection: "column",
|
|
52
|
-
children: processes.map(function(item) {
|
|
51
|
+
children: store.processes.map(function(item) {
|
|
53
52
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChildProcess.default, _object_spread({}, item), item.id);
|
|
54
53
|
})
|
|
55
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport type { ChildProcess as ChildProcessT } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App({ store }) {\n return (\n <Box flexDirection=\"column\">\n {store.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} {...item} />\n ))}\n </Box>\n );\n}\n"],"names":["App","store","Box","flexDirection","processes","map","item","ChildProcess","id"],"mappings":";;;;+BAIA;;;eAAwBA;;;;mBAJJ;mEAEK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEV,SAASA,IAAI,KAAS;QAAT,AAAEC,QAAF,MAAEA;IAC5B,qBACE,qBAACC,QAAG;QAACC,eAAc;kBAChBF,MAAMG,SAAS,CAACC,GAAG,CAAC,SAACC;iCACpB,qBAACC,qBAAY,qBAAmBD,OAAbA,KAAKE,EAAE;;;AAIlC"}
|
package/dist/cjs/createApp.d.cts
CHANGED
package/dist/cjs/createApp.d.ts
CHANGED
package/dist/cjs/createApp.js
CHANGED
|
@@ -10,36 +10,43 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
var _ink = require("ink");
|
|
13
|
+
var _lodashthrottle = /*#__PURE__*/ _interop_require_default(require("lodash.throttle"));
|
|
13
14
|
var _App = /*#__PURE__*/ _interop_require_default(require("./components/App.js"));
|
|
14
|
-
var _ProcessContext = require("./state/ProcessContext.js");
|
|
15
15
|
var _ProcessStore = /*#__PURE__*/ _interop_require_default(require("./state/ProcessStore.js"));
|
|
16
16
|
function _interop_require_default(obj) {
|
|
17
17
|
return obj && obj.__esModule ? obj : {
|
|
18
18
|
default: obj
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
var THROTTLE = 100;
|
|
21
22
|
function createApp() {
|
|
22
23
|
var refCount = 0;
|
|
23
24
|
var store = null;
|
|
24
25
|
var inkApp = null;
|
|
26
|
+
var previousData = null;
|
|
27
|
+
var rerender = function() {
|
|
28
|
+
if (!inkApp || !store) return;
|
|
29
|
+
if (store.data() === previousData) return;
|
|
30
|
+
previousData = store.data();
|
|
31
|
+
inkApp.rerender(/*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {
|
|
32
|
+
store: store
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
var rerenderThrottled = (0, _lodashthrottle.default)(rerender, THROTTLE);
|
|
25
36
|
return {
|
|
26
37
|
retain: function retain(fn) {
|
|
27
38
|
if (++refCount > 1) return fn(store);
|
|
28
39
|
if (store) throw new Error('Not expecting store');
|
|
29
|
-
store = new _ProcessStore.default();
|
|
30
|
-
inkApp = (0, _ink.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
31
|
-
store: store
|
|
32
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {})
|
|
40
|
+
store = new _ProcessStore.default(rerenderThrottled);
|
|
41
|
+
inkApp = (0, _ink.render)(/*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {
|
|
42
|
+
store: store
|
|
33
43
|
}));
|
|
34
44
|
fn(store);
|
|
35
45
|
},
|
|
36
46
|
release: function release(cb) {
|
|
37
47
|
if (--refCount > 0) return cb();
|
|
38
48
|
if (!store) throw new Error('Expecting store');
|
|
39
|
-
|
|
40
|
-
store: store,
|
|
41
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_App.default, {})
|
|
42
|
-
}));
|
|
49
|
+
rerender();
|
|
43
50
|
inkApp.waitUntilExit().then(function() {
|
|
44
51
|
return cb();
|
|
45
52
|
}).catch(cb);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport throttle from 'lodash.throttle';\nimport App from './components/App.js';\nimport { default as Store, type StoreData } from './state/ProcessStore.js';\n\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n\nconst THROTTLE = 100;\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n let previousData: StoreData[] = null;\n const rerender = () => {\n if (!inkApp || !store) return;\n if (store.data() === previousData) return;\n previousData = store.data();\n inkApp.rerender(<App store={store} />);\n };\n const rerenderThrottled = throttle(rerender, THROTTLE);\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n\n store = new Store(rerenderThrottled);\n inkApp = render(<App store={store} />);\n fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) return cb();\n if (!store) throw new Error('Expecting store');\n\n rerender();\n inkApp\n .waitUntilExit()\n .then(() => cb())\n .catch(cb);\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["createApp","THROTTLE","refCount","store","inkApp","previousData","rerender","data","App","rerenderThrottled","throttle","retain","fn","Error","Store","render","release","cb","waitUntilExit","then","catch","unmount","process","stdout","write"],"mappings":";;;;+BAUA;;;eAAwBA;;;;mBAVc;qEACjB;0DACL;mEACiC;;;;;;AAKjD,IAAMC,WAAW;AAEF,SAASD;IACtB,IAAIE,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,IAAIC,eAA4B;IAChC,IAAMC,WAAW;QACf,IAAI,CAACF,UAAU,CAACD,OAAO;QACvB,IAAIA,MAAMI,IAAI,OAAOF,cAAc;QACnCA,eAAeF,MAAMI,IAAI;QACzBH,OAAOE,QAAQ,eAAC,qBAACE,YAAG;YAACL,OAAOA;;IAC9B;IACA,IAAMM,oBAAoBC,IAAAA,uBAAQ,EAACJ,UAAUL;IAE7C,OAAO;QACLU,QAAAA,SAAAA,OAAOC,EAAkB;YACvB,IAAI,EAAEV,WAAW,GAAG,OAAOU,GAAGT;YAC9B,IAAIA,OAAO,MAAM,IAAIU,MAAM;YAE3BV,QAAQ,IAAIW,qBAAK,CAACL;YAClBL,SAASW,IAAAA,WAAM,gBAAC,qBAACP,YAAG;gBAACL,OAAOA;;YAC5BS,GAAGT;QACL;QACAa,SAAAA,SAAAA,QAAQC,EAAmB;YACzB,IAAI,EAAEf,WAAW,GAAG,OAAOe;YAC3B,IAAI,CAACd,OAAO,MAAM,IAAIU,MAAM;YAE5BP;YACAF,OACGc,aAAa,GACbC,IAAI,CAAC;uBAAMF;eACXG,KAAK,CAACH;YACTb,OAAOiB,OAAO;YACdjB,SAAS;YACTD,QAAQ;YACRmB,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
1
|
import type { ChildProcess, ChildProcessUpdate } from '../types.js';
|
|
3
|
-
export
|
|
2
|
+
export type RenderFunction = () => void;
|
|
3
|
+
export type StoreData = ChildProcess[];
|
|
4
|
+
export default class ProcessStore {
|
|
4
5
|
processes: ChildProcess[];
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
onRender: RenderFunction;
|
|
7
|
+
constructor(onRender: RenderFunction);
|
|
8
|
+
data(): StoreData;
|
|
9
|
+
add(process: ChildProcess): void;
|
|
7
10
|
update(id: string, update: ChildProcessUpdate): void;
|
|
8
11
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
1
|
import type { ChildProcess, ChildProcessUpdate } from '../types.js';
|
|
3
|
-
export
|
|
2
|
+
export type RenderFunction = () => void;
|
|
3
|
+
export type StoreData = ChildProcess[];
|
|
4
|
+
export default class ProcessStore {
|
|
4
5
|
processes: ChildProcess[];
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
onRender: RenderFunction;
|
|
7
|
+
constructor(onRender: RenderFunction);
|
|
8
|
+
data(): StoreData;
|
|
9
|
+
add(process: ChildProcess): void;
|
|
7
10
|
update(id: string, update: ChildProcessUpdate): void;
|
|
8
11
|
}
|
|
@@ -8,81 +8,26 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return ProcessStore;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var _events = require("events");
|
|
12
|
-
function _assert_this_initialized(self) {
|
|
13
|
-
if (self === void 0) {
|
|
14
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
15
|
-
}
|
|
16
|
-
return self;
|
|
17
|
-
}
|
|
18
|
-
function _call_super(_this, derived, args) {
|
|
19
|
-
derived = _get_prototype_of(derived);
|
|
20
|
-
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
21
|
-
}
|
|
22
11
|
function _class_call_check(instance, Constructor) {
|
|
23
12
|
if (!(instance instanceof Constructor)) {
|
|
24
13
|
throw new TypeError("Cannot call a class as a function");
|
|
25
14
|
}
|
|
26
15
|
}
|
|
27
|
-
function
|
|
28
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
29
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
30
|
-
};
|
|
31
|
-
return _get_prototype_of(o);
|
|
32
|
-
}
|
|
33
|
-
function _inherits(subClass, superClass) {
|
|
34
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
35
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
36
|
-
}
|
|
37
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
38
|
-
constructor: {
|
|
39
|
-
value: subClass,
|
|
40
|
-
writable: true,
|
|
41
|
-
configurable: true
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
45
|
-
}
|
|
46
|
-
function _possible_constructor_return(self, call) {
|
|
47
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
48
|
-
return call;
|
|
49
|
-
}
|
|
50
|
-
return _assert_this_initialized(self);
|
|
51
|
-
}
|
|
52
|
-
function _set_prototype_of(o, p) {
|
|
53
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
54
|
-
o.__proto__ = p;
|
|
55
|
-
return o;
|
|
56
|
-
};
|
|
57
|
-
return _set_prototype_of(o, p);
|
|
58
|
-
}
|
|
59
|
-
function _type_of(obj) {
|
|
60
|
-
"@swc/helpers - typeof";
|
|
61
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
62
|
-
}
|
|
63
|
-
function _is_native_reflect_construct() {
|
|
64
|
-
try {
|
|
65
|
-
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
66
|
-
} catch (_) {}
|
|
67
|
-
return (_is_native_reflect_construct = function() {
|
|
68
|
-
return !!result;
|
|
69
|
-
})();
|
|
70
|
-
}
|
|
71
|
-
var ProcessStore = /*#__PURE__*/ function(EventEmitter) {
|
|
16
|
+
var ProcessStore = /*#__PURE__*/ function() {
|
|
72
17
|
"use strict";
|
|
73
|
-
|
|
74
|
-
function ProcessStore() {
|
|
18
|
+
function ProcessStore(onRender) {
|
|
75
19
|
_class_call_check(this, ProcessStore);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return _this;
|
|
20
|
+
if (!onRender) throw new Error('missing on render');
|
|
21
|
+
this.processes = [];
|
|
22
|
+
this.onRender = onRender;
|
|
80
23
|
}
|
|
81
24
|
var _proto = ProcessStore.prototype;
|
|
25
|
+
_proto.data = function data() {
|
|
26
|
+
return this.processes;
|
|
27
|
+
};
|
|
82
28
|
_proto.add = function add(process) {
|
|
83
29
|
this.processes.push(process);
|
|
84
|
-
this.
|
|
85
|
-
return process;
|
|
30
|
+
this.onRender();
|
|
86
31
|
};
|
|
87
32
|
_proto.update = function update(id, update) {
|
|
88
33
|
var found = this.processes.find(function(x) {
|
|
@@ -93,8 +38,8 @@ var ProcessStore = /*#__PURE__*/ function(EventEmitter) {
|
|
|
93
38
|
return;
|
|
94
39
|
}
|
|
95
40
|
Object.assign(found, update);
|
|
96
|
-
this.
|
|
41
|
+
this.onRender();
|
|
97
42
|
};
|
|
98
43
|
return ProcessStore;
|
|
99
|
-
}(
|
|
44
|
+
}();
|
|
100
45
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/ProcessStore.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/ProcessStore.ts"],"sourcesContent":["import type { ChildProcess, ChildProcessUpdate } from '../types.js';\n\nexport type RenderFunction = () => void;\nexport type StoreData = ChildProcess[];\n\nexport default class ProcessStore {\n processes: ChildProcess[];\n onRender: RenderFunction;\n\n constructor(onRender: RenderFunction) {\n if (!onRender) throw new Error('missing on render');\n this.processes = [];\n this.onRender = onRender;\n }\n\n data(): StoreData {\n return this.processes;\n }\n\n add(process: ChildProcess): void {\n this.processes.push(process);\n this.onRender();\n }\n\n update(id: string, update: ChildProcessUpdate): void {\n const found = this.processes.find((x) => x.id === id);\n if (!found) {\n console.log(`Process ${id} not found`);\n return;\n }\n Object.assign(found, update);\n this.onRender();\n }\n}\n"],"names":["ProcessStore","onRender","Error","processes","data","add","process","push","update","id","found","find","x","console","log","Object","assign"],"mappings":";;;;;;;eAKqBA;;;;;;;;AAAN,IAAA,AAAMA,6BAAN;;aAAMA,aAIPC,QAAwB;gCAJjBD;QAKjB,IAAI,CAACC,UAAU,MAAM,IAAIC,MAAM;QAC/B,IAAI,CAACC,SAAS,GAAG,EAAE;QACnB,IAAI,CAACF,QAAQ,GAAGA;;iBAPCD;IAUnBI,OAAAA,IAEC,GAFDA,SAAAA;QACE,OAAO,IAAI,CAACD,SAAS;IACvB;IAEAE,OAAAA,GAGC,GAHDA,SAAAA,IAAIC,OAAqB;QACvB,IAAI,CAACH,SAAS,CAACI,IAAI,CAACD;QACpB,IAAI,CAACL,QAAQ;IACf;IAEAO,OAAAA,MAQC,GARDA,SAAAA,OAAOC,EAAU,EAAED,MAA0B;QAC3C,IAAME,QAAQ,IAAI,CAACP,SAAS,CAACQ,IAAI,CAAC,SAACC;mBAAMA,EAAEH,EAAE,KAAKA;;QAClD,IAAI,CAACC,OAAO;YACVG,QAAQC,GAAG,CAAC,AAAC,WAAa,OAAHL,IAAG;YAC1B;QACF;QACAM,OAAOC,MAAM,CAACN,OAAOF;QACrB,IAAI,CAACP,QAAQ;IACf;WA3BmBD"}
|
|
@@ -28,12 +28,10 @@ function _object_spread(target) {
|
|
|
28
28
|
}
|
|
29
29
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
30
30
|
import { Box } from 'ink';
|
|
31
|
-
import { useProcesses } from '../state/ProcessContext.js';
|
|
32
31
|
import ChildProcess from './ChildProcess.js';
|
|
33
|
-
export default function App() {
|
|
34
|
-
const processes = useProcesses();
|
|
32
|
+
export default function App({ store }) {
|
|
35
33
|
return /*#__PURE__*/ _jsx(Box, {
|
|
36
34
|
flexDirection: "column",
|
|
37
|
-
children: processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, _object_spread({}, item), item.id))
|
|
35
|
+
children: store.processes.map((item)=>/*#__PURE__*/ _jsx(ChildProcess, _object_spread({}, item), item.id))
|
|
38
36
|
});
|
|
39
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import { Box } from 'ink';\nimport type { ChildProcess as ChildProcessT } from '../types.js';\nimport ChildProcess from './ChildProcess.js';\n\nexport default function App({ store }) {\n return (\n <Box flexDirection=\"column\">\n {store.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} {...item} />\n ))}\n </Box>\n );\n}\n"],"names":["Box","ChildProcess","App","store","flexDirection","processes","map","item","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAG,QAAQ,MAAM;AAE1B,OAAOC,kBAAkB,oBAAoB;AAE7C,eAAe,SAASC,IAAI,EAAEC,KAAK,EAAE;IACnC,qBACE,KAACH;QAAII,eAAc;kBAChBD,MAAME,SAAS,CAACC,GAAG,CAAC,CAACC,qBACpB,KAACN,iCAA+BM,OAAbA,KAAKC,EAAE;;AAIlC"}
|
package/dist/esm/createApp.d.ts
CHANGED
package/dist/esm/createApp.js
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from 'ink';
|
|
3
|
+
import throttle from 'lodash.throttle';
|
|
3
4
|
import App from './components/App.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { default as Store } from './state/ProcessStore.js';
|
|
6
|
+
const THROTTLE = 100;
|
|
6
7
|
export default function createApp() {
|
|
7
8
|
let refCount = 0;
|
|
8
9
|
let store = null;
|
|
9
10
|
let inkApp = null;
|
|
11
|
+
let previousData = null;
|
|
12
|
+
const rerender = ()=>{
|
|
13
|
+
if (!inkApp || !store) return;
|
|
14
|
+
if (store.data() === previousData) return;
|
|
15
|
+
previousData = store.data();
|
|
16
|
+
inkApp.rerender(/*#__PURE__*/ _jsx(App, {
|
|
17
|
+
store: store
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
const rerenderThrottled = throttle(rerender, THROTTLE);
|
|
10
21
|
return {
|
|
11
22
|
retain (fn) {
|
|
12
23
|
if (++refCount > 1) return fn(store);
|
|
13
24
|
if (store) throw new Error('Not expecting store');
|
|
14
|
-
store = new Store();
|
|
15
|
-
inkApp = render(/*#__PURE__*/ _jsx(
|
|
16
|
-
store: store
|
|
17
|
-
children: /*#__PURE__*/ _jsx(App, {})
|
|
25
|
+
store = new Store(rerenderThrottled);
|
|
26
|
+
inkApp = render(/*#__PURE__*/ _jsx(App, {
|
|
27
|
+
store: store
|
|
18
28
|
}));
|
|
19
29
|
fn(store);
|
|
20
30
|
},
|
|
21
31
|
release (cb) {
|
|
22
32
|
if (--refCount > 0) return cb();
|
|
23
33
|
if (!store) throw new Error('Expecting store');
|
|
24
|
-
|
|
25
|
-
store: store,
|
|
26
|
-
children: /*#__PURE__*/ _jsx(App, {})
|
|
27
|
-
}));
|
|
34
|
+
rerender();
|
|
28
35
|
inkApp.waitUntilExit().then(()=>cb()).catch(cb);
|
|
29
36
|
inkApp.unmount();
|
|
30
37
|
inkApp = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import { type Instance, render } from 'ink';\nimport throttle from 'lodash.throttle';\nimport App from './components/App.js';\nimport { default as Store, type StoreData } from './state/ProcessStore.js';\n\nexport type RetainCallback = (app: Store) => undefined;\nexport type ReleaseCallback = () => undefined;\n\nconst THROTTLE = 100;\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n\n let previousData: StoreData[] = null;\n const rerender = () => {\n if (!inkApp || !store) return;\n if (store.data() === previousData) return;\n previousData = store.data();\n inkApp.rerender(<App store={store} />);\n };\n const rerenderThrottled = throttle(rerender, THROTTLE);\n\n return {\n retain(fn: RetainCallback): undefined {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n\n store = new Store(rerenderThrottled);\n inkApp = render(<App store={store} />);\n fn(store);\n },\n release(cb: ReleaseCallback): undefined {\n if (--refCount > 0) return cb();\n if (!store) throw new Error('Expecting store');\n\n rerender();\n inkApp\n .waitUntilExit()\n .then(() => cb())\n .catch(cb);\n inkApp.unmount();\n inkApp = null;\n store = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["render","throttle","App","default","Store","THROTTLE","createApp","refCount","store","inkApp","previousData","rerender","data","rerenderThrottled","retain","fn","Error","release","cb","waitUntilExit","then","catch","unmount","process","stdout","write"],"mappings":";AAAA,SAAwBA,MAAM,QAAQ,MAAM;AAC5C,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,SAAS,sBAAsB;AACtC,SAASC,WAAWC,KAAK,QAAwB,0BAA0B;AAK3E,MAAMC,WAAW;AAEjB,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAE9B,IAAIC,eAA4B;IAChC,MAAMC,WAAW;QACf,IAAI,CAACF,UAAU,CAACD,OAAO;QACvB,IAAIA,MAAMI,IAAI,OAAOF,cAAc;QACnCA,eAAeF,MAAMI,IAAI;QACzBH,OAAOE,QAAQ,eAAC,KAACT;YAAIM,OAAOA;;IAC9B;IACA,MAAMK,oBAAoBZ,SAASU,UAAUN;IAE7C,OAAO;QACLS,QAAOC,EAAkB;YACvB,IAAI,EAAER,WAAW,GAAG,OAAOQ,GAAGP;YAC9B,IAAIA,OAAO,MAAM,IAAIQ,MAAM;YAE3BR,QAAQ,IAAIJ,MAAMS;YAClBJ,SAAST,qBAAO,KAACE;gBAAIM,OAAOA;;YAC5BO,GAAGP;QACL;QACAS,SAAQC,EAAmB;YACzB,IAAI,EAAEX,WAAW,GAAG,OAAOW;YAC3B,IAAI,CAACV,OAAO,MAAM,IAAIQ,MAAM;YAE5BL;YACAF,OACGU,aAAa,GACbC,IAAI,CAAC,IAAMF,MACXG,KAAK,CAACH;YACTT,OAAOa,OAAO;YACdb,SAAS;YACTD,QAAQ;YACRe,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
1
|
import type { ChildProcess, ChildProcessUpdate } from '../types.js';
|
|
3
|
-
export
|
|
2
|
+
export type RenderFunction = () => void;
|
|
3
|
+
export type StoreData = ChildProcess[];
|
|
4
|
+
export default class ProcessStore {
|
|
4
5
|
processes: ChildProcess[];
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
onRender: RenderFunction;
|
|
7
|
+
constructor(onRender: RenderFunction);
|
|
8
|
+
data(): StoreData;
|
|
9
|
+
add(process: ChildProcess): void;
|
|
7
10
|
update(id: string, update: ChildProcessUpdate): void;
|
|
8
11
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
class ProcessStore {
|
|
2
|
+
data() {
|
|
3
|
+
return this.processes;
|
|
4
|
+
}
|
|
3
5
|
add(process) {
|
|
4
6
|
this.processes.push(process);
|
|
5
|
-
this.
|
|
6
|
-
return process;
|
|
7
|
+
this.onRender();
|
|
7
8
|
}
|
|
8
9
|
update(id, update) {
|
|
9
10
|
const found = this.processes.find((x)=>x.id === id);
|
|
@@ -12,11 +13,12 @@ class ProcessStore extends EventEmitter {
|
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
Object.assign(found, update);
|
|
15
|
-
this.
|
|
16
|
+
this.onRender();
|
|
16
17
|
}
|
|
17
|
-
constructor(){
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
constructor(onRender){
|
|
19
|
+
if (!onRender) throw new Error('missing on render');
|
|
20
|
+
this.processes = [];
|
|
21
|
+
this.onRender = onRender;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
export { ProcessStore as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/ProcessStore.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/state/ProcessStore.ts"],"sourcesContent":["import type { ChildProcess, ChildProcessUpdate } from '../types.js';\n\nexport type RenderFunction = () => void;\nexport type StoreData = ChildProcess[];\n\nexport default class ProcessStore {\n processes: ChildProcess[];\n onRender: RenderFunction;\n\n constructor(onRender: RenderFunction) {\n if (!onRender) throw new Error('missing on render');\n this.processes = [];\n this.onRender = onRender;\n }\n\n data(): StoreData {\n return this.processes;\n }\n\n add(process: ChildProcess): void {\n this.processes.push(process);\n this.onRender();\n }\n\n update(id: string, update: ChildProcessUpdate): void {\n const found = this.processes.find((x) => x.id === id);\n if (!found) {\n console.log(`Process ${id} not found`);\n return;\n }\n Object.assign(found, update);\n this.onRender();\n }\n}\n"],"names":["ProcessStore","data","processes","add","process","push","onRender","update","id","found","find","x","console","log","Object","assign","Error"],"mappings":"AAKe,MAAMA;IAUnBC,OAAkB;QAChB,OAAO,IAAI,CAACC,SAAS;IACvB;IAEAC,IAAIC,OAAqB,EAAQ;QAC/B,IAAI,CAACF,SAAS,CAACG,IAAI,CAACD;QACpB,IAAI,CAACE,QAAQ;IACf;IAEAC,OAAOC,EAAU,EAAED,MAA0B,EAAQ;QACnD,MAAME,QAAQ,IAAI,CAACP,SAAS,CAACQ,IAAI,CAAC,CAACC,IAAMA,EAAEH,EAAE,KAAKA;QAClD,IAAI,CAACC,OAAO;YACVG,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEL,GAAG,UAAU,CAAC;YACrC;QACF;QACAM,OAAOC,MAAM,CAACN,OAAOF;QACrB,IAAI,CAACD,QAAQ;IACf;IAvBA,YAAYA,QAAwB,CAAE;QACpC,IAAI,CAACA,UAAU,MAAM,IAAIU,MAAM;QAC/B,IAAI,CAACd,SAAS,GAAG,EAAE;QACnB,IAAI,CAACI,QAAQ,GAAGA;IAClB;AAoBF;AA5BA,SAAqBN,0BA4BpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawn-term",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Formats spawn with for terminal grouping",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cross-spawn-cb": "^2.2.10",
|
|
44
44
|
"ink": "^6.0.0",
|
|
45
|
+
"lodash.throttle": "^4.1.1",
|
|
45
46
|
"on-one": "^0.1.9",
|
|
46
47
|
"queue-cb": "^1.5.4",
|
|
47
48
|
"react": "^19.1.0"
|