From 33f306d40bd826a4437f404dee22b6b3183ea91e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 17 Sep 2019 22:54:23 -0700 Subject: [PATCH] Add command sending support to console --- .../scripts/components/server/Console.tsx | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/resources/scripts/components/server/Console.tsx b/resources/scripts/components/server/Console.tsx index 2ea31e90e..f35ded898 100644 --- a/resources/scripts/components/server/Console.tsx +++ b/resources/scripts/components/server/Console.tsx @@ -45,6 +45,15 @@ export default () => { line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m', ); + const handleCommandKeydown = (e: React.KeyboardEvent) => { + 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(() => { if (ref.current && !terminal.element) { terminal.open(ref.current); @@ -59,17 +68,12 @@ export default () => { if (connected && instance) { terminal.clear(); - instance - // .addListener('stats', data => console.log(JSON.parse(data))) - .addListener('console output', handleConsoleOutput); - + instance.addListener('console output', handleConsoleOutput); instance.send('send logs'); } return () => { - instance && instance - .removeAllListeners('console output') - .removeAllListeners('stats'); + instance && instance.removeListener('console output', handleConsoleOutput); }; }, [ connected, instance ]); @@ -88,7 +92,12 @@ export default () => {
$
- + handleCommandKeydown(e)} + />