my-airdrop 1.1.1 → 1.1.2
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/bin/cli.js +51 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -24,6 +24,49 @@ for (let i = 0; i < args.length; i++) {
|
|
|
24
24
|
else if (!args[i].startsWith('-')) servePath = path.resolve(args[i]);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// ── Interactive select ───────────────────────────────
|
|
28
|
+
function select(question, options) {
|
|
29
|
+
return new Promise(resolve => {
|
|
30
|
+
let idx = 0;
|
|
31
|
+
|
|
32
|
+
function draw() {
|
|
33
|
+
process.stdout.write('\x1B[2J\x1B[H');
|
|
34
|
+
console.log('');
|
|
35
|
+
console.log(' ' + chalk.bold.hex('#818cf8')('◆ ') + chalk.bold.white('my-airdrop'));
|
|
36
|
+
console.log('');
|
|
37
|
+
console.log(' ' + chalk.gray(question));
|
|
38
|
+
console.log('');
|
|
39
|
+
options.forEach((opt, i) => {
|
|
40
|
+
const cursor = i === idx ? chalk.hex('#818cf8')('●') : chalk.gray('○');
|
|
41
|
+
const label = i === idx ? chalk.white(opt.label) : chalk.gray(opt.label);
|
|
42
|
+
const desc = i === idx ? chalk.gray(' ' + opt.desc) : chalk.gray(' ' + opt.desc);
|
|
43
|
+
console.log(' ' + cursor + ' ' + label + desc);
|
|
44
|
+
});
|
|
45
|
+
console.log('');
|
|
46
|
+
console.log(chalk.gray(' ↑↓ to move · Enter to select'));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
draw();
|
|
50
|
+
process.stdin.setRawMode(true);
|
|
51
|
+
process.stdin.resume();
|
|
52
|
+
process.stdin.setEncoding('utf8');
|
|
53
|
+
|
|
54
|
+
process.stdin.on('data', function handler(key) {
|
|
55
|
+
if (key === '\u0003') { process.stdin.setRawMode(false); process.exit(0); }
|
|
56
|
+
if (key === '\u001B\u005B\u0041' || key === 'k') idx = (idx - 1 + options.length) % options.length; // up
|
|
57
|
+
if (key === '\u001B\u005B\u0042' || key === 'j') idx = (idx + 1) % options.length; // down
|
|
58
|
+
if (key === '\r' || key === '\n') {
|
|
59
|
+
process.stdin.removeListener('data', handler);
|
|
60
|
+
process.stdin.setRawMode(false);
|
|
61
|
+
process.stdin.pause();
|
|
62
|
+
resolve(options[idx].value);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
draw();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
27
70
|
if (!fs.existsSync(servePath) || !fs.statSync(servePath).isDirectory()) {
|
|
28
71
|
console.error(chalk.red(' Not a directory: ' + servePath));
|
|
29
72
|
process.exit(1);
|
|
@@ -85,6 +128,14 @@ function getLocalIP() {
|
|
|
85
128
|
|
|
86
129
|
// ── Main ─────────────────────────────────────────────
|
|
87
130
|
async function main() {
|
|
131
|
+
// Interactive mode if no flags given
|
|
132
|
+
if (process.stdin.isTTY && !args.some(a => a.startsWith('--'))) {
|
|
133
|
+
usePublic = await select('How do you want to share?', [
|
|
134
|
+
{ label: 'Local', desc: '— same WiFi only', value: false },
|
|
135
|
+
{ label: 'Public', desc: '— accessible from anywhere', value: true },
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
|
|
88
139
|
const { count, size } = quickScan(servePath);
|
|
89
140
|
|
|
90
141
|
// Hard limit
|