spawn-term 0.1.2 → 0.1.4

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.
@@ -10,13 +10,13 @@ Object.defineProperty(exports, "default", {
10
10
  }
11
11
  });
12
12
  var _crossspawncb = /*#__PURE__*/ _interop_require_wildcard(require("cross-spawn-cb"));
13
+ var _liluuid = /*#__PURE__*/ _interop_require_default(require("lil-uuid"));
13
14
  var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
14
15
  var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
15
16
  var _createApp = /*#__PURE__*/ _interop_require_default(require("./createApp.cjs"));
16
17
  var _addLines = /*#__PURE__*/ _interop_require_default(require("./lib/addLines.cjs"));
17
18
  var _concatWritable = /*#__PURE__*/ _interop_require_default(require("./lib/concatWritable.cjs"));
18
19
  var _types = require("./types.cjs");
19
- var _lodashthrottle = /*#__PURE__*/ _interop_require_default(require("lodash.throttle"));
20
20
  function _define_property(obj, key, value) {
21
21
  if (key in obj) {
22
22
  Object.defineProperty(obj, key, {
@@ -143,95 +143,112 @@ function _object_without_properties_loose(source, excluded) {
143
143
  return target;
144
144
  }
145
145
  var terminal = (0, _createApp.default)();
146
- var THROTTLE = 100;
147
- var rerender = (0, _lodashthrottle.default)(function() {
148
- terminal.rerender();
149
- }, THROTTLE);
150
146
  function spawnTerminal(command, args, spawnOptions, _options, callback) {
151
147
  var encoding = spawnOptions.encoding, stdio = spawnOptions.stdio, csOptions = _object_without_properties(spawnOptions, [
152
148
  "encoding",
153
149
  "stdio"
154
150
  ]);
155
- terminal.retain();
156
- var item = terminal.addItem({
157
- title: [
158
- command
159
- ].concat(args).join(' '),
160
- state: 'running'
161
- });
162
- terminal.rerender();
163
- var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
164
- var outputs = {
165
- stdout: null,
166
- stderr: null
167
- };
168
- if (cp.stdout && process.stdout.getMaxListeners) {
169
- process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
170
- process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
171
- }
172
- var queue = new _queuecb.default();
173
- if (cp.stdout) {
174
- if (stdio === 'inherit') {
175
- outputs.stdout = (0, _addLines.default)(function(text) {
176
- item.lines.push({
177
- type: _types.LineType.stdout,
178
- text: text
179
- });
180
- rerender();
181
- });
182
- } else {
183
- outputs.stdout = (0, _concatWritable.default)(function(output) {
184
- outputs.stdout.output = output.toString(encoding || 'utf8');
185
- });
151
+ terminal.retain(function(store) {
152
+ var id = (0, _liluuid.default)();
153
+ store.getState().addProcess({
154
+ id: id,
155
+ title: [
156
+ command
157
+ ].concat(args).join(' '),
158
+ state: 'running',
159
+ lines: []
160
+ });
161
+ var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
162
+ var outputs = {
163
+ stdout: null,
164
+ stderr: null
165
+ };
166
+ if (cp.stdout && process.stdout.getMaxListeners) {
167
+ process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
168
+ process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
186
169
  }
187
- queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
188
- 'error',
189
- 'end',
190
- 'close',
191
- 'finish'
192
- ]));
193
- }
194
- if (cp.stderr) {
195
- if (stdio === 'inherit') {
196
- outputs.stderr = (0, _addLines.default)(function(text) {
197
- item.lines.push({
198
- type: _types.LineType.stderr,
199
- text: text
170
+ var queue = new _queuecb.default();
171
+ if (cp.stdout) {
172
+ if (stdio === 'inherit') {
173
+ outputs.stdout = (0, _addLines.default)(function(texts) {
174
+ var item = store.getState().processes.find(function(x) {
175
+ return x.id === id;
176
+ });
177
+ var lines = item.lines.concat(texts.map(function(text) {
178
+ return {
179
+ type: _types.LineType.stdout,
180
+ text: text
181
+ };
182
+ }));
183
+ store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
184
+ lines: lines
185
+ }));
200
186
  });
201
- rerender();
202
- });
203
- } else {
204
- outputs.stderr = (0, _concatWritable.default)(function(output) {
205
- outputs.stderr.output = output.toString(encoding || 'utf8');
206
- });
187
+ } else {
188
+ outputs.stdout = (0, _concatWritable.default)(function(output) {
189
+ outputs.stdout.output = output.toString(encoding || 'utf8');
190
+ });
191
+ }
192
+ queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
193
+ 'error',
194
+ 'end',
195
+ 'close',
196
+ 'finish'
197
+ ]));
207
198
  }
208
- queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
209
- 'error',
210
- 'end',
211
- 'close',
212
- 'finish'
213
- ]));
214
- }
215
- queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
216
- encoding: 'utf8'
217
- })));
218
- queue.await(function(err) {
219
- if (cp.stdout && process.stdout.getMaxListeners) {
220
- process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
221
- process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
199
+ if (cp.stderr) {
200
+ if (stdio === 'inherit') {
201
+ outputs.stderr = (0, _addLines.default)(function(texts) {
202
+ var item = store.getState().processes.find(function(x) {
203
+ return x.id === id;
204
+ });
205
+ var lines = item.lines.concat(texts.map(function(text) {
206
+ return {
207
+ type: _types.LineType.stderr,
208
+ text: text
209
+ };
210
+ }));
211
+ store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
212
+ lines: lines
213
+ }));
214
+ });
215
+ } else {
216
+ outputs.stderr = (0, _concatWritable.default)(function(output) {
217
+ outputs.stderr.output = output.toString(encoding || 'utf8');
218
+ });
219
+ }
220
+ queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
221
+ 'error',
222
+ 'end',
223
+ 'close',
224
+ 'finish'
225
+ ]));
222
226
  }
223
- var res = err ? err : {};
224
- res.stdout = outputs.stdout ? outputs.stdout.output : null;
225
- res.stderr = outputs.stderr ? outputs.stderr.output : null;
226
- res.output = [
227
- res.stdout,
228
- res.stderr,
229
- null
230
- ];
231
- item.state = err ? 'error' : 'success';
232
- terminal.rerender();
233
- terminal.release();
234
- err ? callback(err) : callback(null, res);
227
+ queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
228
+ encoding: 'utf8'
229
+ })));
230
+ queue.await(function(err) {
231
+ if (cp.stdout && process.stdout.getMaxListeners) {
232
+ process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
233
+ process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
234
+ }
235
+ var res = err ? err : {};
236
+ res.stdout = outputs.stdout ? outputs.stdout.output : null;
237
+ res.stderr = outputs.stderr ? outputs.stderr.output : null;
238
+ res.output = [
239
+ res.stdout,
240
+ res.stderr,
241
+ null
242
+ ];
243
+ var item = store.getState().processes.find(function(x) {
244
+ return x.id === id;
245
+ });
246
+ store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
247
+ state: err ? 'error' : 'success'
248
+ }));
249
+ terminal.release();
250
+ err ? callback(err) : callback(null, res);
251
+ });
235
252
  });
236
253
  }
237
254
  /* 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/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nimport throttle from 'lodash.throttle';\nconst THROTTLE = 100;\nconst rerender = throttle(() => {\n terminal.rerender();\n}, THROTTLE);\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, _options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain();\n const item = terminal.addItem({ title: [command].concat(args).join(' '), state: 'running' });\n terminal.rerender();\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\n outputs.stdout = addLines((text) => {\n item.lines.push({ type: LineType.stdout, text });\n rerender();\n });\n } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\n outputs.stderr = addLines((text) => {\n item.lines.push({ type: LineType.stderr, text });\n rerender();\n });\n } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n item.state = err ? 'error' : 'success';\n terminal.rerender();\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n}\n"],"names":["spawnTerminal","terminal","createApp","THROTTLE","rerender","throttle","command","args","spawnOptions","_options","callback","encoding","stdio","csOptions","retain","item","addItem","title","concat","join","state","cp","crossSpawn","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","Queue","addLines","text","lines","push","type","LineType","concatWritable","output","toString","defer","oo","bind","pipe","spawn","worker","await","err","res","release"],"mappings":"AAAA,aAAa;;;;;+BAoBb;;;eAAwBA;;;oEAnB4B;4DACrC;8DACG;gEAEI;+DACD;qEACM;qBAGF;qEAIJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAFrB,IAAMC,WAAWC,IAAAA,kBAAS;AAG1B,IAAMC,WAAW;AACjB,IAAMC,WAAWC,IAAAA,uBAAQ,EAAC;IACxBJ,SAASG,QAAQ;AACnB,GAAGD;AAEY,SAASH,cAAcM,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,QAAyB,EAAEC,QAAQ;IACpI,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElBX,SAASa,MAAM;IACf,IAAMC,OAAOd,SAASe,OAAO,CAAC;QAAEC,OAAO;YAACX;SAAQ,CAACY,MAAM,CAACX,MAAMY,IAAI,CAAC;QAAMC,OAAO;IAAU;IAC1FnB,SAASG,QAAQ;IAEjB,IAAMiB,KAAKC,IAAAA,wBAAU,EAAChB,SAASC,MAAMM;IACrC,IAAMU,UAAU;QAAEC,QAAQ;QAAMC,QAAQ;IAAK;IAE7C,IAAIJ,GAAGG,MAAM,IAAIE,QAAQF,MAAM,CAACG,eAAe,EAAE;QAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;QAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;IACpE;IAEA,IAAME,QAAQ,IAAIC,gBAAK;IACvB,IAAIT,GAAGG,MAAM,EAAE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QF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;YAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;QACpE;QAEA,IAAMqB,MAAOD,MAAMA,MAAM,CAAC;QAC1BC,IAAIxB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACc,MAAM,GAAG;QACtDU,IAAIvB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACa,MAAM,GAAG;QACtDU,IAAIV,MAAM,GAAG;YAACU,IAAIxB,MAAM;YAAEwB,IAAIvB,MAAM;YAAE;SAAK;QAC3CV,KAAKK,KAAK,GAAG2B,MAAM,UAAU;QAC7B9C,SAASG,QAAQ;QACjBH,SAASgD,OAAO;QAChBF,MAAMrC,SAASqC,OAAOrC,SAAS,MAAMsC;IACvC;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, _options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [] });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","_options","callback","encoding","stdio","csOptions","retain","store","id","uuid","getState","addProcess","title","concat","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","concatWritable","output","toString","defer","oo","b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B,GAAGI,MAAM,CAACuB,IAAI,CAACzB,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAI,MAAMgB,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAM1B,IAAI,wCAAKZ;YAAWF,UAAU;;QAClEsB,MAAMsB,KAAK,CAAC,SAACC;YACX,IAAI/B,GAAGG,MAAM,IAAIE,QAAQF,MAAM,CAACG,eAAe,EAAE;gBAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;gBAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;YACpE;YAEA,IAAM0B,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAI7B,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACmB,MAAM,GAAG;YACtDU,IAAI5B,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACkB,MAAM,GAAG;YACtDU,IAAIV,MAAM,GAAG;gBAACU,IAAI7B,MAAM;gBAAE6B,IAAI5B,MAAM;gBAAE;aAAK;YAC3C,IAAMQ,OAAOtB,MAAMG,QAAQ,GAAGoB,SAAS,CAACC,IAAI,CAAC,SAACC;uBAAMA,EAAExB,EAAE,KAAKA;;YAC7DD,MAAMG,QAAQ,GAAG2B,aAAa,CAAC,wCAAKR;gBAAMd,OAAOiC,MAAM,UAAU;;YACjEpD,SAASsD,OAAO;YAChBF,MAAM9C,SAAS8C,OAAO9C,SAAS,MAAM+C;QACvC;IACF;AACF"}
@@ -1,47 +1,24 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _object_spread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _define_property(target, key, source[key]);
25
- });
26
- }
27
- return target;
28
- }
29
- import React from 'react';
1
+ import React, { useContext } from 'react';
2
+ import { useStore } from 'zustand';
3
+ import StoreContext from '../contexts/Store.mjs';
30
4
  import { Box } from '../ink.mjs';
31
5
  import ChildProcess from './ChildProcess.mjs';
32
- export default function App({ list }) {
33
- const running = list.filter((x)=>[
6
+ export default function App() {
7
+ const store = useContext(StoreContext);
8
+ const appState = useStore(store);
9
+ const running = appState.processes.filter((x)=>[
34
10
  'running'
35
11
  ].indexOf(x.state) >= 0);
36
- const done = list.filter((x)=>[
12
+ const done = appState.processes.filter((x)=>[
37
13
  'error',
38
14
  'success'
39
15
  ].indexOf(x.state) >= 0);
40
16
  return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Box, {
41
17
  flexDirection: "column"
42
- }, running.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, _object_spread({
43
- key: item.id
44
- }, item)))), /*#__PURE__*/ React.createElement(Box, {
18
+ }, running.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, {
19
+ key: item.id,
20
+ id: item.id
21
+ }))), /*#__PURE__*/ React.createElement(Box, {
45
22
  flexDirection: "column",
46
23
  borderStyle: "single",
47
24
  borderColor: "black",
@@ -51,7 +28,8 @@ export default function App({ list }) {
51
28
  borderRight: false
52
29
  }), /*#__PURE__*/ React.createElement(Box, {
53
30
  flexDirection: "column"
54
- }, done.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, _object_spread({
55
- key: item.id
56
- }, item)))));
31
+ }, done.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, {
32
+ key: item.id,
33
+ id: item.id
34
+ }))));
57
35
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React from 'react';\nimport { Box } from '../ink.mjs';\nimport type { ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport interface AppProps {\n list: ChildProcessT[];\n}\n\nexport default function App({ list }: AppProps) {\n const running = list.filter((x) => ['running'].indexOf(x.state) >= 0);\n const done = list.filter((x) => ['error', 'success'].indexOf(x.state) >= 0);\n\n return (\n <>\n <Box flexDirection=\"column\">\n {running.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} {...item} />\n ))}\n </Box>\n <Box flexDirection=\"column\" borderStyle=\"single\" borderColor=\"black\" borderBottom={true} borderTop={false} borderLeft={false} borderRight={false} />\n <Box flexDirection=\"column\">\n {done.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} {...item} />\n ))}\n </Box>\n </>\n );\n}\n"],"names":["React","Box","ChildProcess","App","list","running","filter","x","indexOf","state","done","flexDirection","map","item","key","id","borderStyle","borderColor","borderBottom","borderTop","borderLeft","borderRight"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,aAAa;AAEjC,OAAOC,kBAAkB,iBAAiB;AAM1C,eAAe,SAASC,IAAI,EAAEC,IAAI,EAAY;IAC5C,MAAMC,UAAUD,KAAKE,MAAM,CAAC,CAACC,IAAM;YAAC;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IACnE,MAAMC,OAAON,KAAKE,MAAM,CAAC,CAACC,IAAM;YAAC;YAAS;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IAEzE,qBACE,wDACE,oBAACR;QAAIU,eAAc;OAChBN,QAAQO,GAAG,CAAC,CAACC,qBACZ,oBAACX;YAAaY,KAAKD,KAAKE,EAAE;WAAMF,wBAGpC,oBAACZ;QAAIU,eAAc;QAASK,aAAY;QAASC,aAAY;QAAQC,cAAc;QAAMC,WAAW;QAAOC,YAAY;QAAOC,aAAa;sBAC3I,oBAACpB;QAAIU,eAAc;OAChBD,KAAKE,GAAG,CAAC,CAACC,qBACT,oBAACX;YAAaY,KAAKD,KAAKE,EAAE;WAAMF;AAK1C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box } from '../ink.mjs';\nimport type { AppState, ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport default function App() {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const running = appState.processes.filter((x) => ['running'].indexOf(x.state) >= 0);\n const done = appState.processes.filter((x) => ['error', 'success'].indexOf(x.state) >= 0);\n\n return (\n <>\n <Box flexDirection=\"column\">\n {running.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} id={item.id} />\n ))}\n </Box>\n <Box flexDirection=\"column\" borderStyle=\"single\" borderColor=\"black\" borderBottom={true} borderTop={false} borderLeft={false} borderRight={false} />\n <Box flexDirection=\"column\">\n {done.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} id={item.id} />\n ))}\n </Box>\n </>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","ChildProcess","App","store","appState","running","processes","filter","x","indexOf","state","done","flexDirection","map","item","key","id","borderStyle","borderColor","borderBottom","borderTop","borderLeft","borderRight"],"mappings":"AAAA,OAAOA,SAASC,UAAU,QAAQ,QAAQ;AAC1C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,oBAAoB;AAC7C,SAASC,GAAG,QAAQ,aAAa;AAEjC,OAAOC,kBAAkB,iBAAiB;AAE1C,eAAe,SAASC;IACtB,MAAMC,QAAQN,WAAWE;IACzB,MAAMK,WAAWN,SAASK;IAC1B,MAAME,UAAUD,SAASE,SAAS,CAACC,MAAM,CAAC,CAACC,IAAM;YAAC;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IACjF,MAAMC,OAAOP,SAASE,SAAS,CAACC,MAAM,CAAC,CAACC,IAAM;YAAC;YAAS;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IAEvF,qBACE,wDACE,oBAACV;QAAIY,eAAc;OAChBP,QAAQQ,GAAG,CAAC,CAACC,qBACZ,oBAACb;YAAac,KAAKD,KAAKE,EAAE;YAAEA,IAAIF,KAAKE,EAAE;4BAG3C,oBAAChB;QAAIY,eAAc;QAASK,aAAY;QAASC,aAAY;QAAQC,cAAc;QAAMC,WAAW;QAAOC,YAAY;QAAOC,aAAa;sBAC3I,oBAACtB;QAAIY,eAAc;OAChBD,KAAKE,GAAG,CAAC,CAACC,qBACT,oBAACb;YAAac,KAAKD,KAAKE,EAAE;YAAEA,IAAIF,KAAKE,EAAE;;AAKjD"}
@@ -1,4 +1,6 @@
1
- import React from 'react';
1
+ import React, { useContext } from 'react';
2
+ import { useStore } from 'zustand';
3
+ import StoreContext from '../contexts/Store.mjs';
2
4
  import { Box, Text } from '../ink.mjs';
3
5
  import figures from '../lib/figures.mjs';
4
6
  import Spinner from './Spinner.mjs';
@@ -36,7 +38,11 @@ const POINTERS = {
36
38
  color: "yellow"
37
39
  }, figures.pointer)
38
40
  };
39
- export default function ChildProcess({ title, state, lines, isExpanded }) {
41
+ export default function ChildProcess({ id }) {
42
+ const store = useContext(StoreContext);
43
+ const appState = useStore(store);
44
+ const item = appState.processes.find((x)=>x.id === id);
45
+ const { title, state, lines, isExpanded } = item;
40
46
  const icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];
41
47
  const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;
42
48
  const errors = state !== 'running' ? lines.filter((line)=>line.type === LineType.stderr) : [];
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React from 'react';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { Line, State } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n title: string;\n state: State;\n lines: Line[];\n isExpanded?: boolean;\n};\n\nexport default function ChildProcess({ title, state, lines, isExpanded }: ChildProcessProps) {\n const icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];\n const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;\n const errors = state !== 'running' ? lines.filter((line) => line.type === LineType.stderr) : [];\n\n return (\n <Box flexDirection=\"column\">\n <Box>\n <Box marginRight={1}>\n <Text>{icon}</Text>\n </Box>\n <Text>{title}</Text>\n </Box>\n {output ? (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n ) : undefined}\n {errors.length > 0 && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n </Box>\n );\n}\n"],"names":["React","Box","Text","figures","Spinner","LineType","spinner","interval","frames","ICONS","error","color","cross","success","tick","running","POINTERS","pointer","default","ChildProcess","title","state","lines","isExpanded","icon","output","length","undefined","errors","filter","line","type","stderr","flexDirection","marginRight","marginLeft","arrowRight","text","map","index","key","height"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAa;AACvC,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,aAAa,YAAY;AAGhC,SAASC,QAAQ,QAAQ,WAAW;AAEpC,oHAAoH;AACpH,MAAMC,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,MAAMC,QAAQ;IACZC,qBAAO,oBAACR;QAAKS,OAAM;OAAOR,QAAQS,KAAK;IACvCC,uBAAS,oBAACX;QAAKS,OAAM;OAASR,QAAQW,IAAI;IAC1CC,uBAAS,oBAACX,SAAYE;AACxB;AAEA,MAAMU,WAAW;IACfN,qBAAO,oBAACR;QAAKS,OAAM;OAAOR,QAAQc,OAAO;IACzCC,uBAAS,oBAAChB;QAAKS,OAAM;OAAUR,QAAQc,OAAO;AAChD;AASA,eAAe,SAASE,aAAa,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAqB;IACzF,MAAMC,OAAOD,aAAaP,QAAQ,CAACK,MAAM,IAAIL,SAASE,OAAO,GAAGT,KAAK,CAACY,MAAM;IAC5E,MAAMI,SAASJ,UAAU,aAAaC,MAAMI,MAAM,GAAGJ,KAAK,CAACA,MAAMI,MAAM,GAAG,EAAE,GAAGC;IAC/E,MAAMC,SAASP,UAAU,YAAYC,MAAMO,MAAM,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAK1B,SAAS2B,MAAM,IAAI,EAAE;IAE/F,qBACE,oBAAC/B;QAAIgC,eAAc;qBACjB,oBAAChC,yBACC,oBAACA;QAAIiC,aAAa;qBAChB,oBAAChC,YAAMsB,sBAET,oBAACtB,YAAMkB,SAERK,uBACC,oBAACxB;QAAIkC,YAAY;qBACf,oBAACjC;QAAKS,OAAM;OAAQ,GAAGR,QAAQiC,UAAU,CAAC,CAAC,EAAEX,OAAOY,IAAI,EAAE,KAE1DV,WACHC,OAAOF,MAAM,GAAG,mBACf,oBAACzB;QAAIgC,eAAc;QAASE,YAAY;OACrCb,MAAMgB,GAAG,CAAC,CAACR,MAAMS,QAChB,8DAA8D;sBAC9D,oBAACtC;YAAIuC,KAAKD;YAAON,eAAc;YAASQ,QAAQ;yBAC9C,oBAACvC,YAAM4B,KAAKO,IAAI;AAO9B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\nexport default function ChildProcess({ id }: ChildProcessProps) {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const item = appState.processes.find((x) => x.id === id);\n const { title, state, lines, isExpanded } = item;\n\n const icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];\n const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;\n const errors = state !== 'running' ? lines.filter((line) => line.type === LineType.stderr) : [];\n\n return (\n <Box flexDirection=\"column\">\n <Box>\n <Box marginRight={1}>\n <Text>{icon}</Text>\n </Box>\n <Text>{title}</Text>\n </Box>\n {output ? (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n ) : undefined}\n {errors.length > 0 && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n </Box>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","Text","figures","Spinner","LineType","spinner","interval","frames","ICONS","error","color","cross","success","tick","running","POINTERS","pointer","default","ChildProcess","id","store","appState","item","processes","find","x","title","state","lines","isExpanded","icon","output","length","undefined","errors","filter","line","type","stderr","flexDirection","marginRight","marginLeft","arrowRight","text","map","index","key","height"],"mappings":"AAAA,OAAOA,SAASC,UAAU,QAAQ,QAAQ;AAC1C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,oBAAoB;AAC7C,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAa;AACvC,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,aAAa,YAAY;AAGhC,SAASC,QAAQ,QAAQ,WAAW;AAEpC,oHAAoH;AACpH,MAAMC,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,MAAMC,QAAQ;IACZC,qBAAO,oBAACR;QAAKS,OAAM;OAAOR,QAAQS,KAAK;IACvCC,uBAAS,oBAACX;QAAKS,OAAM;OAASR,QAAQW,IAAI;IAC1CC,uBAAS,oBAACX,SAAYE;AACxB;AAEA,MAAMU,WAAW;IACfN,qBAAO,oBAACR;QAAKS,OAAM;OAAOR,QAAQc,OAAO;IACzCC,uBAAS,oBAAChB;QAAKS,OAAM;OAAUR,QAAQc,OAAO;AAChD;AAMA,eAAe,SAASE,aAAa,EAAEC,EAAE,EAAqB;IAC5D,MAAMC,QAAQvB,WAAWE;IACzB,MAAMsB,WAAWvB,SAASsB;IAC1B,MAAME,OAAOD,SAASE,SAAS,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEN,EAAE,KAAKA;IACrD,MAAM,EAAEO,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGP;IAE5C,MAAMQ,OAAOD,aAAad,QAAQ,CAACY,MAAM,IAAIZ,SAASE,OAAO,GAAGT,KAAK,CAACmB,MAAM;IAC5E,MAAMI,SAASJ,UAAU,aAAaC,MAAMI,MAAM,GAAGJ,KAAK,CAACA,MAAMI,MAAM,GAAG,EAAE,GAAGC;IAC/E,MAAMC,SAASP,UAAU,YAAYC,MAAMO,MAAM,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAKjC,SAASkC,MAAM,IAAI,EAAE;IAE/F,qBACE,oBAACtC;QAAIuC,eAAc;qBACjB,oBAACvC,yBACC,oBAACA;QAAIwC,aAAa;qBAChB,oBAACvC,YAAM6B,sBAET,oBAAC7B,YAAMyB,SAERK,uBACC,oBAAC/B;QAAIyC,YAAY;qBACf,oBAACxC;QAAKS,OAAM;OAAQ,GAAGR,QAAQwC,UAAU,CAAC,CAAC,EAAEX,OAAOY,IAAI,EAAE,KAE1DV,WACHC,OAAOF,MAAM,GAAG,mBACf,oBAAChC;QAAIuC,eAAc;QAASE,YAAY;OACrCb,MAAMgB,GAAG,CAAC,CAACR,MAAMS,QAChB,8DAA8D;sBAC9D,oBAAC7C;YAAI8C,KAAKD;YAAON,eAAc;YAASQ,QAAQ;yBAC9C,oBAAC9C,YAAMmC,KAAKO,IAAI;AAO9B"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export default /*#__PURE__*/ createContext(undefined);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/contexts/Store.tsx"],"sourcesContent":["import { createContext } from 'react';\nexport default createContext(undefined);\n"],"names":["createContext","undefined"],"mappings":"AAAA,SAASA,aAAa,QAAQ,QAAQ;AACtC,6BAAeA,cAAcC,WAAW"}
@@ -1,73 +1,47 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _object_spread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _define_property(target, key, source[key]);
25
- });
26
- }
27
- return target;
28
- }
29
- import uuid from 'lil-uuid';
30
1
  import React from 'react';
2
+ import resolveOnce from 'resolve-once-cb';
3
+ import { createStore } from 'zustand';
31
4
  import App from './components/App.mjs';
5
+ import StoreContext from './contexts/Store.mjs';
32
6
  // @ts-ignore
33
7
  import { render } from './ink.mjs';
8
+ const initialize = resolveOnce((cb)=>setTimeout(()=>cb(), 0));
34
9
  export default function createApp() {
35
10
  let refCount = 0;
36
- let list = null;
11
+ let store = null;
37
12
  let inkApp = null;
13
+ const _waiting = [];
38
14
  return {
39
- addItem (data) {
40
- if (!list) throw new Error('Expecting list');
41
- const item = _object_spread({
42
- id: uuid(),
43
- title: '',
44
- state: 'pending',
45
- lines: []
46
- }, data);
47
- list.push(item);
48
- return item;
49
- },
50
- rerender () {
51
- if (inkApp) inkApp.rerender(/*#__PURE__*/ React.createElement(App, {
52
- list: list
53
- }));
54
- },
55
- retain () {
56
- if (++refCount > 1) return;
57
- if (inkApp) throw new Error('Not expecting app');
58
- list = [];
59
- inkApp = render(/*#__PURE__*/ React.createElement(App, {
60
- list: list
61
- }), {
62
- patchConsole: false
15
+ retain (fn) {
16
+ initialize(()=>{
17
+ if (++refCount > 1) return fn(store);
18
+ if (store) throw new Error('Not expecting store');
19
+ store = createStore()((set)=>({
20
+ processes: [],
21
+ addProcess: (process1)=>set((state)=>({
22
+ processes: [
23
+ ...state.processes,
24
+ process1
25
+ ]
26
+ })),
27
+ updateProcess: (process1)=>set((state)=>({
28
+ processes: state.processes.map((x)=>x.id === process1.id ? process1 : x)
29
+ }))
30
+ }));
31
+ inkApp = render(/*#__PURE__*/ React.createElement(StoreContext.Provider, {
32
+ value: store
33
+ }, /*#__PURE__*/ React.createElement(App, null)), {
34
+ patchConsole: false
35
+ });
36
+ return fn(store);
63
37
  });
64
38
  },
65
39
  release () {
66
40
  if (--refCount > 0) return;
67
- if (!inkApp) throw new Error('Expecting app');
41
+ if (!store) throw new Error('Expecting store');
42
+ store = null;
68
43
  inkApp.unmount();
69
44
  inkApp = null;
70
- list = null;
71
45
  process.stdout.write('\x1b[?25h'); // show cursor
72
46
  }
73
47
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import uuid from 'lil-uuid';\nimport React from 'react';\nimport App from './components/App';\n// @ts-ignore\nimport { type Instance, render } from './ink.mjs';\nimport type { ChildProcess } from './types';\n\nexport default function createApp() {\n let refCount = 0;\n let list: ChildProcess[] | null = null;\n let inkApp: Instance | null = null;\n\n return {\n addItem(data: Partial<ChildProcess>) {\n if (!list) throw new Error('Expecting list');\n const item = { id: uuid(), title: '', state: 'pending', lines: [], ...data } as ChildProcess;\n list.push(item);\n return item;\n },\n rerender() {\n if (inkApp) inkApp.rerender(<App list={list} />);\n },\n retain() {\n if (++refCount > 1) return;\n if (inkApp) throw new Error('Not expecting app');\n list = [];\n inkApp = render(<App list={list} />, { patchConsole: false });\n },\n release() {\n if (--refCount > 0) return;\n if (!inkApp) throw new Error('Expecting app');\n inkApp.unmount();\n inkApp = null;\n list = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["uuid","React","App","render","createApp","refCount","list","inkApp","addItem","data","Error","item","id","title","state","lines","push","rerender","retain","patchConsole","release","unmount","process","stdout","write"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,UAAU,WAAW;AAC5B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,SAAS,mBAAmB;AACnC,aAAa;AACb,SAAwBC,MAAM,QAAQ,YAAY;AAGlD,eAAe,SAASC;IACtB,IAAIC,WAAW;IACf,IAAIC,OAA8B;IAClC,IAAIC,SAA0B;IAE9B,OAAO;QACLC,SAAQC,IAA2B;YACjC,IAAI,CAACH,MAAM,MAAM,IAAII,MAAM;YAC3B,MAAMC,OAAO;gBAAEC,IAAIZ;gBAAQa,OAAO;gBAAIC,OAAO;gBAAWC,OAAO,EAAE;eAAKN;YACtEH,KAAKU,IAAI,CAACL;YACV,OAAOA;QACT;QACAM;YACE,IAAIV,QAAQA,OAAOU,QAAQ,eAAC,oBAACf;gBAAII,MAAMA;;QACzC;QACAY;YACE,IAAI,EAAEb,WAAW,GAAG;YACpB,IAAIE,QAAQ,MAAM,IAAIG,MAAM;YAC5BJ,OAAO,EAAE;YACTC,SAASJ,qBAAO,oBAACD;gBAAII,MAAMA;gBAAU;gBAAEa,cAAc;YAAM;QAC7D;QACAC;YACE,IAAI,EAAEf,WAAW,GAAG;YACpB,IAAI,CAACE,QAAQ,MAAM,IAAIG,MAAM;YAC7BH,OAAOc,OAAO;YACdd,SAAS;YACTD,OAAO;YACPgB,QAAQC,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport resolveOnce from 'resolve-once-cb';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nconst initialize = resolveOnce((cb) => setTimeout(() => cb(), 0));\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n const _waiting = [];\n\n return {\n retain(fn) {\n initialize(() => {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => set((state) => ({ processes: [...state.processes, process] })),\n updateProcess: (process) => set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) })),\n }));\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n });\n },\n release() {\n if (--refCount > 0) return;\n if (!store) throw new Error('Expecting store');\n store = null;\n inkApp.unmount();\n inkApp = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["React","resolveOnce","createStore","App","StoreContext","render","initialize","cb","setTimeout","createApp","refCount","store","inkApp","_waiting","retain","fn","Error","set","processes","addProcess","process","state","updateProcess","map","x","id","Provider","value","patchConsole","release","unmount","stdout","write"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,iBAAiB,kBAAkB;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,OAAOC,SAAS,mBAAmB;AACnC,OAAOC,kBAAkB,mBAAmB;AAE5C,aAAa;AACb,SAAwBC,MAAM,QAAQ,YAAY;AAGlD,MAAMC,aAAaL,YAAY,CAACM,KAAOC,WAAW,IAAMD,MAAM;AAE9D,eAAe,SAASE;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAC9B,MAAMC,WAAW,EAAE;IAEnB,OAAO;QACLC,QAAOC,EAAE;YACPT,WAAW;gBACT,IAAI,EAAEI,WAAW,GAAG,OAAOK,GAAGJ;gBAC9B,IAAIA,OAAO,MAAM,IAAIK,MAAM;gBAC3BL,QAAQT,cAAwB,CAACe,MAAS,CAAA;wBACxCC,WAAW,EAAE;wBACbC,YAAY,CAACC,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAW;2CAAIG,MAAMH,SAAS;wCAAEE;qCAAQ;gCAAC,CAAA;wBACpFE,eAAe,CAACF,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAWG,MAAMH,SAAS,CAACK,GAAG,CAAC,CAACC,IAAOA,EAAEC,EAAE,KAAKL,SAAQK,EAAE,GAAGL,WAAUI;gCAAI,CAAA;oBAC3H,CAAA;gBACAZ,SAASP,qBACP,oBAACD,aAAasB,QAAQ;oBAACC,OAAOhB;iCAC5B,oBAACR,aAEH;oBAAEyB,cAAc;gBAAM;gBAExB,OAAOb,GAAGJ;YACZ;QACF;QACAkB;YACE,IAAI,EAAEnB,WAAW,GAAG;YACpB,IAAI,CAACC,OAAO,MAAM,IAAIK,MAAM;YAC5BL,QAAQ;YACRC,OAAOkB,OAAO;YACdlB,SAAS;YACTQ,QAAQW,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
@@ -1,18 +1,20 @@
1
1
  import { Writable } from 'readable-stream';
2
2
  const regEx = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g;
3
- export default function addLines(addLine) {
3
+ export default function addLines(fn) {
4
4
  let last = '';
5
5
  const stream = new Writable({
6
6
  write (chunk, _enc, callback) {
7
7
  const more = last + chunk.toString('utf8');
8
8
  const lines = more.split(regEx);
9
9
  last = lines.pop();
10
- lines.forEach((line)=>addLine(line));
10
+ if (lines.length) fn(lines);
11
11
  callback();
12
12
  }
13
13
  });
14
14
  stream.on('finish', ()=>{
15
- if (last.length) addLine(last);
15
+ if (last.length) fn([
16
+ last
17
+ ]);
16
18
  last = '';
17
19
  });
18
20
  return stream;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nconst regEx = /\\r\\n|[\\n\\v\\f\\r\\x85\\u2028\\u2029]/g;\n\nexport default function addLines(addLine) {\n let last = '';\n\n const stream = new Writable({\n write(chunk, _enc, callback) {\n const more = last + chunk.toString('utf8');\n const lines = more.split(regEx);\n last = lines.pop();\n lines.forEach((line) => addLine(line));\n callback();\n },\n });\n stream.on('finish', () => {\n if (last.length) addLine(last);\n last = '';\n });\n return stream;\n}\n"],"names":["Writable","regEx","addLines","addLine","last","stream","write","chunk","_enc","callback","more","toString","lines","split","pop","forEach","line","on","length"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,MAAMC,QAAQ;AAEd,eAAe,SAASC,SAASC,OAAO;IACtC,IAAIC,OAAO;IAEX,MAAMC,SAAS,IAAIL,SAAS;QAC1BM,OAAMC,KAAK,EAAEC,IAAI,EAAEC,QAAQ;YACzB,MAAMC,OAAON,OAAOG,MAAMI,QAAQ,CAAC;YACnC,MAAMC,QAAQF,KAAKG,KAAK,CAACZ;YACzBG,OAAOQ,MAAME,GAAG;YAChBF,MAAMG,OAAO,CAAC,CAACC,OAASb,QAAQa;YAChCP;QACF;IACF;IACAJ,OAAOY,EAAE,CAAC,UAAU;QAClB,IAAIb,KAAKc,MAAM,EAAEf,QAAQC;QACzBA,OAAO;IACT;IACA,OAAOC;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nconst regEx = /\\r\\n|[\\n\\v\\f\\r\\x85\\u2028\\u2029]/g;\n\nexport default function addLines(fn) {\n let last = '';\n\n const stream = new Writable({\n write(chunk, _enc, callback) {\n const more = last + chunk.toString('utf8');\n const lines = more.split(regEx);\n last = lines.pop();\n if (lines.length) fn(lines);\n callback();\n },\n });\n stream.on('finish', () => {\n if (last.length) fn([last]);\n last = '';\n });\n return stream;\n}\n"],"names":["Writable","regEx","addLines","fn","last","stream","write","chunk","_enc","callback","more","toString","lines","split","pop","length","on"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,MAAMC,QAAQ;AAEd,eAAe,SAASC,SAASC,EAAE;IACjC,IAAIC,OAAO;IAEX,MAAMC,SAAS,IAAIL,SAAS;QAC1BM,OAAMC,KAAK,EAAEC,IAAI,EAAEC,QAAQ;YACzB,MAAMC,OAAON,OAAOG,MAAMI,QAAQ,CAAC;YACnC,MAAMC,QAAQF,KAAKG,KAAK,CAACZ;YACzBG,OAAOQ,MAAME,GAAG;YAChB,IAAIF,MAAMG,MAAM,EAAEZ,GAAGS;YACrBH;QACF;IACF;IACAJ,OAAOW,EAAE,CAAC,UAAU;QAClB,IAAIZ,KAAKW,MAAM,EAAEZ,GAAG;YAACC;SAAK;QAC1BA,OAAO;IACT;IACA,OAAOC;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n};\n\nexport enum LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n};\n"],"names":["LineType"],"mappings":"AAAA,aAAa;AAOb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n};\n\nexport enum LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n isExpanded: boolean;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n"],"names":["LineType"],"mappings":"AAAA,aAAa;AAOb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}