cli-whatsapp 0.1.4 → 0.1.5

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.
@@ -162,6 +162,19 @@ function printAbove(state, text) {
162
162
  process.stdout.write(text + '\n');
163
163
  state.rl.prompt(true);
164
164
  }
165
+ /**
166
+ * Replace the line the user just submitted (their echoed input) with `text`, so
167
+ * an outgoing message shows once as a bubble instead of appearing twice. Called
168
+ * synchronously while processing the line, when the cursor sits just below the
169
+ * submitted input.
170
+ */
171
+ function replaceSubmitted(state, text) {
172
+ readline.moveCursor(process.stdout, 0, -1); // up onto the submitted-input line
173
+ readline.cursorTo(process.stdout, 0);
174
+ readline.clearLine(process.stdout, 0);
175
+ process.stdout.write(text + '\n');
176
+ state.rl.prompt(true);
177
+ }
165
178
  function bubble(who, text, incoming) {
166
179
  const time = c.gray(formatTime(Date.now(), loadConfig().preferences.time24h));
167
180
  const name = incoming ? c.cyan(who) : c.green('me');
@@ -233,14 +246,20 @@ async function ensureConnected(state) {
233
246
  }
234
247
  }
235
248
  // ---- sending ---------------------------------------------------------------
236
- async function sendTo(state, jid, name, content, meta) {
249
+ async function sendTo(state, jid, name, content, meta, replaceInput = false) {
250
+ const wasLive = state.status === 'live';
237
251
  const conn = await ensureConnected(state);
238
252
  if (!conn)
239
253
  return;
240
254
  try {
241
255
  await sendContent(conn.sock, jid, content, meta);
242
256
  const echo = meta.type === 'text' ? meta.previewText : `[${meta.type}] ${meta.previewText}`;
243
- printAbove(state, bubble(name, echo, false));
257
+ // Replace the just-typed input with the bubble so it shows once — but only
258
+ // when we were already live (no "connecting…" lines were printed in between).
259
+ if (replaceInput && wasLive)
260
+ replaceSubmitted(state, bubble(name, echo, false));
261
+ else
262
+ printAbove(state, bubble(name, echo, false));
244
263
  refreshNames();
245
264
  }
246
265
  catch (err) {
@@ -349,11 +368,7 @@ async function handle(state, raw) {
349
368
  if (at) {
350
369
  try {
351
370
  const built = buildMediaContent(at.file, at.caption || undefined);
352
- await sendTo(state, jid, name, built.content, {
353
- previewText: at.caption || `[${built.kind}]`,
354
- type: built.kind,
355
- mediaPath: built.path,
356
- });
371
+ await sendTo(state, jid, name, built.content, { previewText: at.caption || `[${built.kind}]`, type: built.kind, mediaPath: built.path }, true);
357
372
  }
358
373
  catch (err) {
359
374
  printError(err);
@@ -361,7 +376,7 @@ async function handle(state, raw) {
361
376
  return;
362
377
  }
363
378
  // Otherwise plain text.
364
- await sendTo(state, jid, name, { text: line }, { previewText: line, type: 'text' });
379
+ await sendTo(state, jid, name, { text: line }, { previewText: line, type: 'text' }, true);
365
380
  return;
366
381
  }
367
382
  const [cmdRaw, ...args] = tokenize(line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-whatsapp",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A lightweight, fast, terminal-first WhatsApp client. Read, search, send, media, groups, and live notifications — from your terminal.",
5
5
  "type": "module",
6
6
  "bin": {