@luutuankiet/gsd-reader 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.cjs +52 -37
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -179,46 +179,61 @@ async function commandDump() {
|
|
|
179
179
|
|
|
180
180
|
function promptPassword(prompt) {
|
|
181
181
|
return new Promise((resolve) => {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
182
|
+
const input = process.stdin;
|
|
183
|
+
const output = process.stdout;
|
|
184
|
+
|
|
185
|
+
const cleanup = () => {
|
|
186
|
+
if (input.isTTY) {
|
|
187
|
+
input.setRawMode(false);
|
|
188
|
+
}
|
|
189
|
+
input.pause();
|
|
190
|
+
input.removeListener('data', onData);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const finish = () => {
|
|
194
|
+
cleanup();
|
|
195
|
+
output.write('\n');
|
|
196
|
+
resolve(password);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
output.write(prompt);
|
|
200
|
+
|
|
195
201
|
let password = '';
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
202
|
+
|
|
203
|
+
if (input.isTTY) {
|
|
204
|
+
input.setRawMode(true);
|
|
205
|
+
}
|
|
206
|
+
input.resume();
|
|
207
|
+
|
|
208
|
+
const onData = (chunk) => {
|
|
209
|
+
const char = chunk.toString('utf8');
|
|
210
|
+
|
|
211
|
+
if (char === '\u0003') {
|
|
212
|
+
cleanup();
|
|
213
|
+
output.write('\n');
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (char === '\r' || char === '\n' || char === '\u0004') {
|
|
218
|
+
finish();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (char === '\u007f' || char === '\b') {
|
|
223
|
+
if (password.length > 0) {
|
|
215
224
|
password = password.slice(0, -1);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
break;
|
|
225
|
+
output.write('\b \b');
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
220
228
|
}
|
|
221
|
-
|
|
229
|
+
|
|
230
|
+
if (char >= ' ' && char <= '~') {
|
|
231
|
+
password += char;
|
|
232
|
+
output.write('*');
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
input.on('data', onData);
|
|
222
237
|
});
|
|
223
238
|
}
|
|
224
239
|
|