11import fs from 'node:fs' ;
22import path from 'node:path' ;
33import os from 'node:os' ;
4+ import { stdin } from 'node:process' ;
45
56import { pkg , config , configPath , configDownloadPath } from '../src/static.js'
67import { parse } from '../src/parse.js' ;
@@ -141,6 +142,7 @@ async function read(path) {
141142 console . log ( `(Press ${ key } to finish input.)\n` ) ;
142143 try {
143144 content = await readFromStdin ( ) ;
145+ console . log ( '\n' ) ;
144146 } catch ( e ) {
145147 error = e ;
146148 }
@@ -166,18 +168,10 @@ async function read(path) {
166168function readFromStdin ( ) {
167169 return new Promise ( ( resolve , reject ) => {
168170 let content = '' ;
169- process . stdin . setEncoding ( 'utf8' ) ;
170- process . stdin . on ( 'readable' , ( ) => {
171- let chunk ;
172- while ( ( chunk = process . stdin . read ( ) ) ) {
173- content += chunk ;
174- }
175- } ) ;
176- process . stdin . on ( 'end' , ( ) => {
177- console . log ( '\n' ) ;
178- resolve ( content ) ;
179- } ) ;
180- process . stdin . on ( 'error' , reject ) ;
171+ stdin . setEncoding ( 'utf8' ) ;
172+ stdin . on ( 'data' , c => content += c ) ;
173+ stdin . on ( 'end' , ( ) => resolve ( content ) ) ;
174+ stdin . on ( 'error' , reject ) ;
181175 } ) ;
182176}
183177
0 commit comments