cli-whatsapp 0.1.2 → 0.1.3
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/dist/cli/commands/shell.js +61 -17
- package/package.json +1 -1
|
@@ -544,6 +544,29 @@ export async function shell() {
|
|
|
544
544
|
// listener, so rl.line already includes the just-typed character.
|
|
545
545
|
readline.emitKeypressEvents(process.stdin);
|
|
546
546
|
let pickerOpen = false;
|
|
547
|
+
// Commands whose <chat> argument gets the live chat picker. "final" = chat is
|
|
548
|
+
// the last arg (run on pick); "then" = chat then more input (send/sendfile).
|
|
549
|
+
const CHAT_FINAL = new Set(['open', 'history', 'pin', 'unpin', 'archive', 'unarchive']);
|
|
550
|
+
const CHAT_THEN = new Set(['send', 'sendfile']);
|
|
551
|
+
const clearLine = () => rl.write(null, { ctrl: true, name: 'u' });
|
|
552
|
+
// Open the chat picker for a command, then insert/run with the chosen chat.
|
|
553
|
+
const chatPickInto = async (cmd) => {
|
|
554
|
+
const items = listChats(3000, true).map((ch) => ({
|
|
555
|
+
value: displayName(ch),
|
|
556
|
+
desc: truncate((ch.lastMessage ?? '').replace(/\s+/g, ' '), 30),
|
|
557
|
+
}));
|
|
558
|
+
const chat = await pickFromList('Select a chat', items, '');
|
|
559
|
+
clearLine();
|
|
560
|
+
if (!chat)
|
|
561
|
+
return; // cancelled → empty line
|
|
562
|
+
const q = /\s/.test(chat) ? `"${chat}"` : chat; // quote names with spaces
|
|
563
|
+
if (CHAT_THEN.has(cmd))
|
|
564
|
+
rl.write(`/${cmd} ${q} `); // wait for message/file
|
|
565
|
+
else {
|
|
566
|
+
queue.push(`/${cmd} ${q}`); // run right away
|
|
567
|
+
void pump();
|
|
568
|
+
}
|
|
569
|
+
};
|
|
547
570
|
process.stdin.on('keypress', (str, _key) => {
|
|
548
571
|
void _key;
|
|
549
572
|
if (!process.stdin.isTTY || pickerOpen || busy)
|
|
@@ -551,26 +574,48 @@ export async function shell() {
|
|
|
551
574
|
// `/` menu — only when it's the first character on the line.
|
|
552
575
|
if (str === '/' && rl.line === '/') {
|
|
553
576
|
pickerOpen = true;
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
577
|
+
void (async () => {
|
|
578
|
+
try {
|
|
579
|
+
const picked = await pickFromList('Slash Commands', SLASH_ITEMS, '');
|
|
580
|
+
clearLine();
|
|
581
|
+
if (!picked)
|
|
582
|
+
return; // cancelled — leave the line empty
|
|
583
|
+
const cmd = picked.slice(1);
|
|
584
|
+
if (CHAT_FINAL.has(cmd) || CHAT_THEN.has(cmd)) {
|
|
585
|
+
await chatPickInto(cmd); // chain straight into the chat picker
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const item = SLASH_ITEMS.find((i) => i.value === picked);
|
|
589
|
+
if (item && !item.args) {
|
|
590
|
+
queue.push(picked); // no args → run now
|
|
591
|
+
void pump();
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
rl.write(picked + ' '); // needs (non-chat) args → wait
|
|
595
|
+
}
|
|
564
596
|
}
|
|
565
|
-
|
|
566
|
-
|
|
597
|
+
finally {
|
|
598
|
+
pickerOpen = false;
|
|
567
599
|
}
|
|
568
|
-
})
|
|
569
|
-
.finally(() => {
|
|
570
|
-
pickerOpen = false;
|
|
571
|
-
});
|
|
600
|
+
})();
|
|
572
601
|
return;
|
|
573
602
|
}
|
|
603
|
+
// Space right after a chat command (typed manually) → open the chat picker.
|
|
604
|
+
if (str === ' ') {
|
|
605
|
+
const m = rl.line.match(/^\/(open|history|pin|unpin|archive|unarchive|send|sendfile) $/);
|
|
606
|
+
if (m) {
|
|
607
|
+
pickerOpen = true;
|
|
608
|
+
void (async () => {
|
|
609
|
+
try {
|
|
610
|
+
await chatPickInto(m[1]);
|
|
611
|
+
}
|
|
612
|
+
finally {
|
|
613
|
+
pickerOpen = false;
|
|
614
|
+
}
|
|
615
|
+
})();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
574
619
|
// `@` file picker — only with a chat open and at a fresh token boundary.
|
|
575
620
|
if (str === '@' && state.active) {
|
|
576
621
|
const before = rl.line.slice(0, Math.max(0, rl.cursor - 1)).replace(/@$/, '');
|
|
@@ -579,7 +624,6 @@ export async function shell() {
|
|
|
579
624
|
pickerOpen = true;
|
|
580
625
|
pickFile(process.cwd())
|
|
581
626
|
.then((picked) => {
|
|
582
|
-
// Quote paths with spaces so the whole path is treated as one token.
|
|
583
627
|
if (picked)
|
|
584
628
|
rl.write(picked.includes(' ') ? `"${picked}"` : picked);
|
|
585
629
|
else
|
package/package.json
CHANGED