forked from vadimdemedes/ink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubprocess-output.tsx
More file actions
33 lines (28 loc) · 790 Bytes
/
subprocess-output.tsx
File metadata and controls
33 lines (28 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import childProcess from 'node:child_process';
import type Buffer from 'node:buffer';
import React from 'react';
import stripAnsi from 'strip-ansi';
import {render, Text, Box} from '../../src/index.js';
function SubprocessOutput() {
const [output, setOutput] = React.useState('');
React.useEffect(() => {
const subProcess = childProcess.spawn('npm', [
'run',
'example',
'examples/jest'
]);
subProcess.stdout.on('data', (newOutput: Buffer) => {
const lines = stripAnsi(newOutput.toString('utf8')).split('\n');
setOutput(lines.slice(-5).join('\n'));
});
}, [setOutput]);
return (
<Box flexDirection="column" padding={1}>
<Text>Сommand output:</Text>
<Box marginTop={1}>
<Text>{output}</Text>
</Box>
</Box>
);
}
render(<SubprocessOutput />);