spawn-term 0.1.21 → 0.1.23
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/ChildProcess.cjs +1 -24
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/lib/ansiRegex.cjs +22 -0
- package/dist/cjs/lib/ansiRegex.cjs.map +1 -0
- package/dist/cjs/worker.cjs +4 -2
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +1 -18
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/lib/ansiRegex.mjs +10 -0
- package/dist/esm/lib/ansiRegex.mjs.map +1 -0
- package/dist/esm/worker.mjs +4 -2
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/lib/ansiRegex.d.ts +3 -0
- package/package.json +1 -1
|
@@ -102,7 +102,7 @@ function Output(param) {
|
|
|
102
102
|
marginLeft: 2
|
|
103
103
|
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
104
104
|
color: "gray"
|
|
105
|
-
},
|
|
105
|
+
}, output.text));
|
|
106
106
|
}
|
|
107
107
|
function Lines(param) {
|
|
108
108
|
var lines = param.lines;
|
|
@@ -120,26 +120,6 @@ function Lines(param) {
|
|
|
120
120
|
}, line.text)));
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
|
-
var HEADINGS = [
|
|
124
|
-
_figures.default.tick,
|
|
125
|
-
_figures.default.cross,
|
|
126
|
-
spinner.frames[0]
|
|
127
|
-
];
|
|
128
|
-
function filterHeadings(lines) {
|
|
129
|
-
var _loop = function(i) {
|
|
130
|
-
var line = lines[i];
|
|
131
|
-
if (!HEADINGS.some(function(x) {
|
|
132
|
-
return line[0] === x;
|
|
133
|
-
})) return "break";
|
|
134
|
-
headings.push(line);
|
|
135
|
-
};
|
|
136
|
-
var headings = [];
|
|
137
|
-
for(var i = 0; i < lines.length; i++){
|
|
138
|
-
var _ret = _loop(i);
|
|
139
|
-
if (_ret === "break") break;
|
|
140
|
-
}
|
|
141
|
-
return headings;
|
|
142
|
-
}
|
|
143
123
|
function ChildProcess(param) {
|
|
144
124
|
var id = param.id;
|
|
145
125
|
var store = (0, _react.useContext)(_Store.default);
|
|
@@ -157,7 +137,6 @@ function ChildProcess(param) {
|
|
|
157
137
|
lines: lines
|
|
158
138
|
}));
|
|
159
139
|
}
|
|
160
|
-
var headings = filterHeadings(lines);
|
|
161
140
|
var errors = lines.filter(function(line) {
|
|
162
141
|
return line.type === _types.LineType.stderr;
|
|
163
142
|
});
|
|
@@ -168,8 +147,6 @@ function ChildProcess(param) {
|
|
|
168
147
|
flexDirection: "column"
|
|
169
148
|
}, /*#__PURE__*/ _react.default.createElement(Header, {
|
|
170
149
|
item: item
|
|
171
|
-
}), headings.length > 0 && /*#__PURE__*/ _react.default.createElement(Lines, {
|
|
172
|
-
lines: headings
|
|
173
150
|
}), state === 'running' && output && /*#__PURE__*/ _react.default.createElement(Output, {
|
|
174
151
|
output: output
|
|
175
152
|
}), errors.length > 0 && /*#__PURE__*/ _react.default.createElement(Lines, {
|
|
@@ -1 +1 @@
|
|
|
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\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{
|
|
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\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{output.text}</Text>\n </Box>\n );\n}\n\nfunction Lines({ lines }) {\n return (\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 color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\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 { state, lines, expanded } = item;\n\n if (expanded) {\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n <Lines lines={lines} />\n </Box>\n );\n }\n const errors = lines.filter((line) => line.type === LineType.stderr);\n const output = lines.filter((line) => line.text.length > 0).pop();\n\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\n </Box>\n );\n}\n"],"names":["ChildProcess","spinner","interval","frames","ICONS","error","Text","color","figures","cross","success","tick","running","Spinner","Header","item","group","title","state","icon","Box","marginRight","bold","pointer","Output","output","marginLeft","text","Lines","lines","flexDirection","map","line","index","key","height","type","LineType","stderr","id","store","useContext","StoreContext","appState","useStore","processes","find","x","expanded","errors","filter","length","pop"],"mappings":";;;;+BA4DA;;;eAAwBA;;;6DA5DU;uBACT;4DACA;mBACC;8DACN;8DACA;qBAGK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,oHAAoH;AACpH,IAAMC,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,IAAMC,QAAQ;IACZC,qBAAO,6BAACC,SAAI;QAACC,OAAM;OAAOC,gBAAO,CAACC,KAAK;IACvCC,uBAAS,6BAACJ,SAAI;QAACC,OAAM;OAASC,gBAAO,CAACG,IAAI;IAC1CC,uBAAS,6BAACC,gBAAO,EAAKZ;AACxB;AAMA,SAASa,OAAO,KAAQ;QAAR,AAAEC,OAAF,MAAEA;IAChB,IAAQC,QAAwBD,KAAxBC,OAAOC,QAAiBF,KAAjBE,OAAOC,QAAUH,KAAVG;IACtB,IAAMC,OAAOf,KAAK,CAACc,MAAM;IAEzB,qBACE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I,MAAMqB,MAAM,CAAC,SAAClB;eAASA,KAAKL,IAAI,CAACwB,MAAM,GAAG;OAAGC,GAAG;IAE/D,qBACE,6BAAChC,QAAG;QAACU,eAAc;qBACjB,6BAAChB;QAAOC,MAAMA;QACbG,UAAU,aAAaO,wBAAU,6BAACD;QAAOC,QAAQA;QACjDwB,OAAOE,MAAM,GAAG,mBAAK,6BAACvB;QAAMC,OAAOoB;;AAG1C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// https://github.com/chalk/ansi-regex/blob/main/index.js
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return ansiRegex;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
function ansiRegex() {
|
|
13
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_onlyFirst = _ref.onlyFirst, onlyFirst = _ref_onlyFirst === void 0 ? false : _ref_onlyFirst;
|
|
14
|
+
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
15
|
+
var ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
|
|
16
|
+
var pattern = [
|
|
17
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?".concat(ST, ")"),
|
|
18
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
|
|
19
|
+
].join('|');
|
|
20
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
21
|
+
}
|
|
22
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/ansiRegex.ts"],"sourcesContent":["// https://github.com/chalk/ansi-regex/blob/main/index.js\nexport default function ansiRegex({ onlyFirst = false } = {}) {\n // Valid string terminator sequences are BEL, ESC\\, and 0x9c\n const ST = '(?:\\\\u0007|\\\\u001B\\\\u005C|\\\\u009C)';\n const pattern = [`[\\\\u001B\\\\u009B][[\\\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]+)*|[a-zA-Z\\\\d]+(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*)?${ST})`, '(?:(?:\\\\d{1,4}(?:;\\\\d{0,4})*)?[\\\\dA-PR-TZcf-nq-uy=><~]))'].join('|');\n\n return new RegExp(pattern, onlyFirst ? undefined : 'g');\n}\n"],"names":["ansiRegex","onlyFirst","ST","pattern","join","RegExp","undefined"],"mappings":"AAAA,yDAAyD;;;;;+BACzD;;;eAAwBA;;;AAAT,SAASA;QAAU,OAAA,iEAAwB,CAAC,oBAAzB,KAAEC,WAAAA,wCAAY;IAC9C,4DAA4D;IAC5D,IAAMC,KAAK;IACX,IAAMC,UAAU;QAAE,uHAAyH,OAAHD,IAAG;QAAI;KAA2D,CAACE,IAAI,CAAC;IAEhN,OAAO,IAAIC,OAAOF,SAASF,YAAYK,YAAY;AACrD"}
|
package/dist/cjs/worker.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
|
15
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
16
16
|
var _createApp = /*#__PURE__*/ _interop_require_default(require("./createApp.cjs"));
|
|
17
17
|
var _addLines = /*#__PURE__*/ _interop_require_default(require("./lib/addLines.cjs"));
|
|
18
|
+
var _ansiRegex = /*#__PURE__*/ _interop_require_default(require("./lib/ansiRegex.cjs"));
|
|
18
19
|
var _concatWritable = /*#__PURE__*/ _interop_require_default(require("./lib/concatWritable.cjs"));
|
|
19
20
|
var _formatArguments = /*#__PURE__*/ _interop_require_default(require("./lib/formatArguments.cjs"));
|
|
20
21
|
var _types = require("./types.cjs");
|
|
@@ -143,6 +144,7 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
143
144
|
}
|
|
144
145
|
return target;
|
|
145
146
|
}
|
|
147
|
+
var ansiRegex = (0, _ansiRegex.default)();
|
|
146
148
|
var terminal = (0, _createApp.default)();
|
|
147
149
|
function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
148
150
|
var encoding = spawnOptions.encoding, stdio = spawnOptions.stdio, csOptions = _object_without_properties(spawnOptions, [
|
|
@@ -174,7 +176,7 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
174
176
|
var lines = item.lines.concat(texts.map(function(text) {
|
|
175
177
|
return {
|
|
176
178
|
type: _types.LineType.stdout,
|
|
177
|
-
text: text
|
|
179
|
+
text: text.replace(ansiRegex, '')
|
|
178
180
|
};
|
|
179
181
|
}));
|
|
180
182
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
@@ -196,7 +198,7 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
196
198
|
var lines = item.lines.concat(texts.map(function(text) {
|
|
197
199
|
return {
|
|
198
200
|
type: _types.LineType.stderr,
|
|
199
|
-
text: text
|
|
201
|
+
text: text.replace(ansiRegex, '')
|
|
200
202
|
};
|
|
201
203
|
}));
|
|
202
204
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
package/dist/cjs/worker.cjs.map
CHANGED
|
@@ -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 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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\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: encoding || 'utf8' }));\n queue.await((err) => {\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 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","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable","toString"],"mappings":"AAAA,aAAa;;;;;+
|
|
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 _ansiRegex from './lib/ansiRegex';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst ansiRegex = _ansiRegex();\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\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: text.replace(ansiRegex, '') })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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: text.replace(ansiRegex, '') })));\n store.getState().updateProcess({ ...item, lines });\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 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\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\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: encoding || 'utf8' }));\n queue.await((err) => {\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 err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawnTerminal","ansiRegex","_ansiRegex","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","uuid","getState","addProcess","title","concat","formatArguments","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","replace","updateProcess","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable","toString"],"mappings":"AAAA,aAAa;;;;;+BAkBb;;;eAAwBA;;;oEAjB4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;gEACE;qEACI;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,YAAYC,IAAAA,kBAAU;AAC5B,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASJ,cAAcK,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,SAACC;YACf,IAAMC,KAAKC,IAAAA,gBAAI;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|
|
47
|
-
},
|
|
47
|
+
}, output.text));
|
|
48
48
|
}
|
|
49
49
|
function Lines({ lines }) {
|
|
50
50
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
@@ -59,20 +59,6 @@ function Lines({ lines }) {
|
|
|
59
59
|
color: line.type === LineType.stderr ? 'red' : 'black'
|
|
60
60
|
}, line.text))));
|
|
61
61
|
}
|
|
62
|
-
const HEADINGS = [
|
|
63
|
-
figures.tick,
|
|
64
|
-
figures.cross,
|
|
65
|
-
spinner.frames[0]
|
|
66
|
-
];
|
|
67
|
-
function filterHeadings(lines) {
|
|
68
|
-
const headings = [];
|
|
69
|
-
for(let i = 0; i < lines.length; i++){
|
|
70
|
-
const line = lines[i];
|
|
71
|
-
if (!HEADINGS.some((x)=>line[0] === x)) break;
|
|
72
|
-
headings.push(line);
|
|
73
|
-
}
|
|
74
|
-
return headings;
|
|
75
|
-
}
|
|
76
62
|
export default function ChildProcess({ id }) {
|
|
77
63
|
const store = useContext(StoreContext);
|
|
78
64
|
const appState = useStore(store);
|
|
@@ -87,15 +73,12 @@ export default function ChildProcess({ id }) {
|
|
|
87
73
|
lines: lines
|
|
88
74
|
}));
|
|
89
75
|
}
|
|
90
|
-
const headings = filterHeadings(lines);
|
|
91
76
|
const errors = lines.filter((line)=>line.type === LineType.stderr);
|
|
92
77
|
const output = lines.filter((line)=>line.text.length > 0).pop();
|
|
93
78
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
94
79
|
flexDirection: "column"
|
|
95
80
|
}, /*#__PURE__*/ React.createElement(Header, {
|
|
96
81
|
item: item
|
|
97
|
-
}), headings.length > 0 && /*#__PURE__*/ React.createElement(Lines, {
|
|
98
|
-
lines: headings
|
|
99
82
|
}), state === 'running' && output && /*#__PURE__*/ React.createElement(Output, {
|
|
100
83
|
output: output
|
|
101
84
|
}), errors.length > 0 && /*#__PURE__*/ React.createElement(Lines, {
|
|
@@ -1 +1 @@
|
|
|
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\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{
|
|
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\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Header({ item }) {\n const { group, title, state } = item;\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n}\n\nfunction Output({ output }) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{output.text}</Text>\n </Box>\n );\n}\n\nfunction Lines({ lines }) {\n return (\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 color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\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 { state, lines, expanded } = item;\n\n if (expanded) {\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n <Lines lines={lines} />\n </Box>\n );\n }\n const errors = lines.filter((line) => line.type === LineType.stderr);\n const output = lines.filter((line) => line.text.length > 0).pop();\n\n return (\n <Box flexDirection=\"column\">\n <Header item={item} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\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","Header","item","group","title","state","icon","marginRight","bold","pointer","Output","output","marginLeft","text","Lines","lines","flexDirection","map","line","index","key","height","type","stderr","ChildProcess","id","store","appState","processes","find","x","expanded","errors","filter","length","pop"],"mappings":"AAAA,OAAOA,SAASC,UAAU,QAAQ,QAAQ;AAC1C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,oBAAoB;AAC7C,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAa;AACv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,SAAS0C;IAC1B,MAAMxB,OAAOyB,SAASC,SAAS,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEL,EAAE,KAAKA;IACrD,MAAM,EAAEpB,KAAK,EAAEU,KAAK,EAAEgB,QAAQ,EAAE,GAAG7B;IAEnC,IAAI6B,UAAU;QACZ,qBACE,oBAAC7C;YAAI8B,eAAc;yBACjB,oBAACf;YAAOC,MAAMA;0BACd,oBAACY;YAAMC,OAAOA;;IAGpB;IACA,MAAMiB,SAASjB,MAAMkB,MAAM,CAAC,CAACf,OAASA,KAAKI,IAAI,KAAKhC,SAASiC,MAAM;IACnE,MAAMZ,SAASI,MAAMkB,MAAM,CAAC,CAACf,OAASA,KAAKL,IAAI,CAACqB,MAAM,GAAG,GAAGC,GAAG;IAE/D,qBACE,oBAACjD;QAAI8B,eAAc;qBACjB,oBAACf;QAAOC,MAAMA;QACbG,UAAU,aAAaM,wBAAU,oBAACD;QAAOC,QAAQA;QACjDqB,OAAOE,MAAM,GAAG,mBAAK,oBAACpB;QAAMC,OAAOiB;;AAG1C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// https://github.com/chalk/ansi-regex/blob/main/index.js
|
|
2
|
+
export default function ansiRegex({ onlyFirst = false } = {}) {
|
|
3
|
+
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
4
|
+
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
|
|
5
|
+
const pattern = [
|
|
6
|
+
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
|
|
7
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
|
|
8
|
+
].join('|');
|
|
9
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/ansiRegex.ts"],"sourcesContent":["// https://github.com/chalk/ansi-regex/blob/main/index.js\nexport default function ansiRegex({ onlyFirst = false } = {}) {\n // Valid string terminator sequences are BEL, ESC\\, and 0x9c\n const ST = '(?:\\\\u0007|\\\\u001B\\\\u005C|\\\\u009C)';\n const pattern = [`[\\\\u001B\\\\u009B][[\\\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]+)*|[a-zA-Z\\\\d]+(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*)?${ST})`, '(?:(?:\\\\d{1,4}(?:;\\\\d{0,4})*)?[\\\\dA-PR-TZcf-nq-uy=><~]))'].join('|');\n\n return new RegExp(pattern, onlyFirst ? undefined : 'g');\n}\n"],"names":["ansiRegex","onlyFirst","ST","pattern","join","RegExp","undefined"],"mappings":"AAAA,yDAAyD;AACzD,eAAe,SAASA,UAAU,EAAEC,YAAY,KAAK,EAAE,GAAG,CAAC,CAAC;IAC1D,4DAA4D;IAC5D,MAAMC,KAAK;IACX,MAAMC,UAAU;QAAC,CAAC,oHAAoH,EAAED,GAAG,CAAC,CAAC;QAAE;KAA2D,CAACE,IAAI,CAAC;IAEhN,OAAO,IAAIC,OAAOF,SAASF,YAAYK,YAAY;AACrD"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -84,9 +84,11 @@ import oo from 'on-one';
|
|
|
84
84
|
import Queue from 'queue-cb';
|
|
85
85
|
import createApp from './createApp.mjs';
|
|
86
86
|
import addLines from './lib/addLines.mjs';
|
|
87
|
+
import _ansiRegex from './lib/ansiRegex.mjs';
|
|
87
88
|
import concatWritable from './lib/concatWritable.mjs';
|
|
88
89
|
import formatArguments from './lib/formatArguments.mjs';
|
|
89
90
|
import { LineType } from './types.mjs';
|
|
91
|
+
const ansiRegex = _ansiRegex();
|
|
90
92
|
const terminal = createApp();
|
|
91
93
|
export default function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
92
94
|
const { encoding, stdio } = spawnOptions, csOptions = _object_without_properties(spawnOptions, [
|
|
@@ -115,7 +117,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
115
117
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
116
118
|
const lines = item.lines.concat(texts.map((text)=>({
|
|
117
119
|
type: LineType.stdout,
|
|
118
|
-
text
|
|
120
|
+
text: text.replace(ansiRegex, '')
|
|
119
121
|
})));
|
|
120
122
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
121
123
|
lines
|
|
@@ -133,7 +135,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
133
135
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
134
136
|
const lines = item.lines.concat(texts.map((text)=>({
|
|
135
137
|
type: LineType.stderr,
|
|
136
|
-
text
|
|
138
|
+
text: text.replace(ansiRegex, '')
|
|
137
139
|
})));
|
|
138
140
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
139
141
|
lines
|
package/dist/esm/worker.mjs.map
CHANGED
|
@@ -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 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';\nimport formatArguments from './lib/formatArguments';\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\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 queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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 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 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\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\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: encoding || 'utf8' }));\n queue.await((err) => {\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 err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","concatWritable","formatArguments","LineType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","texts","item","processes","find","x","map","text","type","updateProcess","defer","bind","pipe","worker","await","err","res","output","setTimeout","release","toString"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,cAAc;AACpC,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,oBAAoB,uBAAuB;AAClD,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,
|
|
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 _ansiRegex from './lib/ansiRegex';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst ansiRegex = _ansiRegex();\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 if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\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: text.replace(ansiRegex, '') })));\n store.getState().updateProcess({ ...item, lines });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\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: text.replace(ansiRegex, '') })));\n store.getState().updateProcess({ ...item, lines });\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 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\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\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: encoding || 'utf8' }));\n queue.await((err) => {\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 err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","_ansiRegex","concatWritable","formatArguments","LineType","ansiRegex","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","queue","texts","item","processes","find","x","map","text","type","replace","updateProcess","defer","bind","pipe","worker","await","err","res","output","setTimeout","release","toString"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,cAAc;AACpC,OAAOC,cAAc,iBAAiB;AACtC,OAAOC,gBAAgB,kBAAkB;AACzC,OAAOC,oBAAoB,uBAAuB;AAClD,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,YAAYJ;AAClB,MAAMK,WAAWP;AAEjB,eAAe,SAASQ,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAA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