@@ -41,9 +41,10 @@ mergeInto(LibraryManager.library, {
41
41
} ,
42
42
close : function ( stream ) {
43
43
// flush any pending line data
44
- if ( stream . tty . output . length ) {
45
- stream . tty . ops . put_char ( stream . tty , { { { charCode ( '\n' ) } } } ) ;
46
- }
44
+ stream . tty . ops . flush ( stream . tty ) ;
45
+ } ,
46
+ flush : function ( stream ) {
47
+ stream . tty . ops . flush ( stream . tty ) ;
47
48
} ,
48
49
read : function ( stream , buffer , offset , length , pos /* ignored */ ) {
49
50
if ( ! stream . tty || ! stream . tty . ops . get_char ) {
@@ -123,6 +124,12 @@ mergeInto(LibraryManager.library, {
123
124
}
124
125
return tty . input . shift ( ) ;
125
126
} ,
127
+ flush : function ( tty ) {
128
+ if ( tty . output && tty . output . length > 0 ) {
129
+ Module [ 'print' ] ( tty . output . join ( '' ) ) ;
130
+ tty . output = [ ] ;
131
+ }
132
+ } ,
126
133
put_char : function ( tty , val ) {
127
134
if ( val === null || val === { { { charCode ( '\n' ) } } } ) {
128
135
Module [ 'print' ] ( tty . output . join ( '' ) ) ;
@@ -140,7 +147,13 @@ mergeInto(LibraryManager.library, {
140
147
} else {
141
148
tty . output . push ( TTY . utf8 . processCChar ( val ) ) ;
142
149
}
143
- }
150
+ } ,
151
+ flush : function ( tty ) {
152
+ if ( tty . output && tty . output . length > 0 ) {
153
+ Module [ 'printErr' ] ( tty . output . join ( '' ) ) ;
154
+ tty . output = [ ] ;
155
+ }
156
+ }
144
157
}
145
158
}
146
159
} ) ;
0 commit comments