@@ -45,6 +45,15 @@ export default () => {
4545 line . replace ( / (?: \r \n | \r | \n ) $ / im, '' ) + '\u001b[0m' ,
4646 ) ;
4747
48+ const handleCommandKeydown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
49+ if ( e . key !== 'Enter' || ( e . key === 'Enter' && e . currentTarget . value . length < 1 ) ) {
50+ return ;
51+ }
52+
53+ instance && instance . send ( 'send command' , e . currentTarget . value ) ;
54+ e . currentTarget . value = '' ;
55+ } ;
56+
4857 useEffect ( ( ) => {
4958 if ( ref . current && ! terminal . element ) {
5059 terminal . open ( ref . current ) ;
@@ -59,17 +68,12 @@ export default () => {
5968 if ( connected && instance ) {
6069 terminal . clear ( ) ;
6170
62- instance
63- // .addListener('stats', data => console.log(JSON.parse(data)))
64- . addListener ( 'console output' , handleConsoleOutput ) ;
65-
71+ instance . addListener ( 'console output' , handleConsoleOutput ) ;
6672 instance . send ( 'send logs' ) ;
6773 }
6874
6975 return ( ) => {
70- instance && instance
71- . removeAllListeners ( 'console output' )
72- . removeAllListeners ( 'stats' ) ;
76+ instance && instance . removeListener ( 'console output' , handleConsoleOutput ) ;
7377 } ;
7478 } , [ connected , instance ] ) ;
7579
@@ -88,7 +92,12 @@ export default () => {
8892 < div className = { 'rounded-b bg-neutral-900 text-neutral-100 flex' } >
8993 < div className = { 'flex-no-shrink p-2 font-bold' } > $</ div >
9094 < div className = { 'w-full' } >
91- < input type = { 'text' } className = { 'bg-transparent text-neutral-100 p-2 pl-0 w-full' } />
95+ < input
96+ type = { 'text' }
97+ disabled = { ! instance || ! connected }
98+ className = { 'bg-transparent text-neutral-100 p-2 pl-0 w-full' }
99+ onKeyDown = { e => handleCommandKeydown ( e ) }
100+ />
92101 </ div >
93102 </ div >
94103 </ div >
0 commit comments