@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.
Files changed (2) hide show
  1. package/cli.cjs +52 -37
  2. 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 rl = readline.createInterface({
183
- input: process.stdin,
184
- output: process.stdout,
185
- });
186
-
187
- // Hide input (works on most terminals)
188
- process.stdout.write(prompt);
189
-
190
- // For password masking, we need to handle raw mode
191
- if (process.stdin.isTTY) {
192
- process.stdin.setRawMode(true);
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
- process.stdin.on('data', (char) => {
198
- char = char.toString();
199
-
200
- switch (char) {
201
- case '\n':
202
- case '\r':
203
- case '\u0004': // Ctrl+D
204
- if (process.stdin.isTTY) {
205
- process.stdin.setRawMode(false);
206
- }
207
- process.stdout.write('\n');
208
- rl.close();
209
- resolve(password);
210
- break;
211
- case '\u0003': // Ctrl+C
212
- process.exit(1);
213
- break;
214
- case '\u007F': // Backspace
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
- break;
217
- default:
218
- password += char;
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luutuankiet/gsd-reader",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Interactive Worklog Reader for GSD-Lite WORK.md files with live reload",
5
5
  "keywords": [
6
6
  "gsd-lite",