Add command sending support to console
This commit is contained in:
parent
498badc0bc
commit
33f306d40b
1 changed files with 17 additions and 8 deletions
|
@ -45,6 +45,15 @@ export default () => {
|
||||||
line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (e.key !== 'Enter' || (e.key === 'Enter' && e.currentTarget.value.length < 1)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance && instance.send('send command', e.currentTarget.value);
|
||||||
|
e.currentTarget.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref.current && !terminal.element) {
|
if (ref.current && !terminal.element) {
|
||||||
terminal.open(ref.current);
|
terminal.open(ref.current);
|
||||||
|
@ -59,17 +68,12 @@ export default () => {
|
||||||
if (connected && instance) {
|
if (connected && instance) {
|
||||||
terminal.clear();
|
terminal.clear();
|
||||||
|
|
||||||
instance
|
instance.addListener('console output', handleConsoleOutput);
|
||||||
// .addListener('stats', data => console.log(JSON.parse(data)))
|
|
||||||
.addListener('console output', handleConsoleOutput);
|
|
||||||
|
|
||||||
instance.send('send logs');
|
instance.send('send logs');
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
instance && instance
|
instance && instance.removeListener('console output', handleConsoleOutput);
|
||||||
.removeAllListeners('console output')
|
|
||||||
.removeAllListeners('stats');
|
|
||||||
};
|
};
|
||||||
}, [ connected, instance ]);
|
}, [ connected, instance ]);
|
||||||
|
|
||||||
|
@ -88,7 +92,12 @@ export default () => {
|
||||||
<div className={'rounded-b bg-neutral-900 text-neutral-100 flex'}>
|
<div className={'rounded-b bg-neutral-900 text-neutral-100 flex'}>
|
||||||
<div className={'flex-no-shrink p-2 font-bold'}>$</div>
|
<div className={'flex-no-shrink p-2 font-bold'}>$</div>
|
||||||
<div className={'w-full'}>
|
<div className={'w-full'}>
|
||||||
<input type={'text'} className={'bg-transparent text-neutral-100 p-2 pl-0 w-full'}/>
|
<input
|
||||||
|
type={'text'}
|
||||||
|
disabled={!instance || !connected}
|
||||||
|
className={'bg-transparent text-neutral-100 p-2 pl-0 w-full'}
|
||||||
|
onKeyDown={e => handleCommandKeydown(e)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue