File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export interface ITerminal {
4
4
5
5
reset : ( ) => void ;
6
6
write : ( data : string ) => void ;
7
+ input : ( data : string ) => void ;
7
8
onData : ( cb : ( data : string ) => void ) => void ;
8
9
}
9
10
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ export class TerminalPanel implements ITerminal {
66
66
67
67
private _terminal ?: ITerminal ;
68
68
private _process ?: WebContainerProcess ;
69
- private _data : string [ ] = [ ] ;
69
+ private _data : { data : string ; type : 'input' | 'echo' } [ ] = [ ] ;
70
70
private _onData ?: ( data : string ) => void ;
71
71
72
72
constructor (
@@ -130,11 +130,24 @@ export class TerminalPanel implements ITerminal {
130
130
}
131
131
}
132
132
133
+ /** @internal */
133
134
write ( data : string ) {
134
135
if ( this . _terminal ) {
135
136
this . _terminal . write ( data ) ;
136
137
} else {
137
- this . _data . push ( data ) ;
138
+ this . _data . push ( { data, type : 'echo' } ) ;
139
+ }
140
+ }
141
+
142
+ input ( data : string ) {
143
+ if ( this . type !== 'terminal' ) {
144
+ throw new Error ( 'Cannot write data to output-only terminal' ) ;
145
+ }
146
+
147
+ if ( this . _terminal ) {
148
+ this . _terminal . input ( data ) ;
149
+ } else {
150
+ this . _data . push ( { data, type : 'input' } ) ;
138
151
}
139
152
}
140
153
@@ -166,8 +179,12 @@ export class TerminalPanel implements ITerminal {
166
179
* @param terminal The terminal.
167
180
*/
168
181
attachTerminal ( terminal : ITerminal ) {
169
- for ( const data of this . _data ) {
170
- terminal . write ( data ) ;
182
+ for ( const { type, data } of this . _data ) {
183
+ if ( type === 'echo' ) {
184
+ terminal . write ( data ) ;
185
+ } else {
186
+ terminal . input ( data ) ;
187
+ }
171
188
}
172
189
173
190
this . _data = [ ] ;
You can’t perform that action at this time.
0 commit comments