@cloud411716/fancy-webnovel 1.0.14 → 1.0.16

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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { existsSync } from 'fs';
9
9
  import { join } from 'path';
10
- import { notify, llmFollowup } from '../../infra.js';
10
+ import { notify, llmFollowup, StatusLine } from '../../infra.js';
11
11
  import { runScans } from './scraper.js';
12
12
  import * as qidian from './platforms/qidian.js';
13
13
  import * as fanqie from './platforms/fanqie.js';
@@ -196,18 +196,19 @@ export function apply(ctx) {
196
196
  // ---------- in-process scraping (no subprocess) ----------
197
197
 
198
198
  // Register scan-progress listeners before scraping starts, clean up after.
199
- // Each fired event sends an ASCII spinner followup so the user sees live
200
- // progress instead of a blank screen while the scraper runs.
199
+ // StatusLine.update() uses session surfaceOp replace so the status stays
200
+ // at the same log position and doesn't accumulate or scroll away.
201
201
  const disposers = [];
202
+ const statusLine = new StatusLine(session);
202
203
  let currentRankLabel = '';
203
204
 
204
205
  disposers.push(ctx.events.on('fancy/scan:start', (_ctx, platform, _channel, _type, label) => {
205
206
  currentRankLabel = label;
206
- notify(session, `[${SPINNER[_spinnerIdx++ % 4]}] 正在采集:${platformLabel(platform)} ${label} …`);
207
+ statusLine.update(`[${SPINNER[_spinnerIdx++ % 4]}] 正在采集:${platformLabel(platform)} ${label} …`);
207
208
  }));
208
209
 
209
210
  disposers.push(ctx.events.on('fancy/scan:rank-done', (_ctx, _platform, _channel, _type, ok, written) => {
210
- notify(session, `[${SPINNER[_spinnerIdx++ % 4]}] ${currentRankLabel} ${ok ? `✓ 写入 ${written} 条` : '✗ 失败'}`);
211
+ statusLine.update(`[${SPINNER[_spinnerIdx++ % 4]}] ${currentRankLabel} ${ok ? `✓ 写入 ${written} 条` : '✗ 失败'}`);
211
212
  }));
212
213
 
213
214
  const { totalBooks, totalFiles, failedRanks, lastReceipt } = await runScans(
@@ -217,8 +218,9 @@ export function apply(ctx) {
217
218
  signal,
218
219
  );
219
220
 
220
- // Clean up progress listeners; runScans is done.
221
+ // Clean up progress listeners and clear the status bar.
221
222
  for (const d of disposers) d();
223
+ statusLine.clear();
222
224
 
223
225
  // ---------- output results ----------
224
226
  if (lastReceipt && totalFiles > 0) {
package/infra.js CHANGED
@@ -2,10 +2,11 @@
2
2
  * infra.js — DSH Plugin Core Infrastructure
3
3
  *
4
4
  * Provides:
5
- * notify(session, text) — append a user-facing message to the session log
5
+ * notify(session, text) — append a user-facing message to the session log
6
6
  * llmFollowup(invocation,prompt)— hand a prompt to the LLM as a user message
7
+ * StatusLine(session) — in-place updatable status bar via surfaceOp replace
7
8
  * scanProgress(ctx, phase, data)— emit structured scan progress events
8
- * sleep(ctx, ms) — DSH-native promise delay via ctx.timeout()
9
+ * sleep(ctx, ms) — DSH-native promise delay via ctx.timeout()
9
10
  *
10
11
  * All fancy-* plugins import from this file.
11
12
  */
@@ -31,6 +32,45 @@ export function notify(session, text) {
31
32
  );
32
33
  }
33
34
 
35
+ // --------------------------------------------------------------------------
36
+ // StatusLine — in-place updatable status bar using session surfaceOp replace
37
+ // --------------------------------------------------------------------------
38
+
39
+ /**
40
+ * Appends a single session event and updates it in-place on subsequent calls
41
+ * using session's surfaceOp replace mechanism. The event always stays at the
42
+ * same log position; only its content changes — visually a terminal status bar.
43
+ *
44
+ * Usage:
45
+ * const status = new StatusLine(session);
46
+ * status.update('Working…');
47
+ * status.update('Done ✓');
48
+ * status.clear();
49
+ */
50
+ export class StatusLine {
51
+ #session;
52
+ #seq;
53
+
54
+ constructor(session) { this.#session = session; }
55
+
56
+ update(text) {
57
+ const event = this.#seq
58
+ ? this.#session.append(
59
+ 'fancy/status',
60
+ { content: [{ type: 'text', text }], source: { kind: 'user' } },
61
+ { surfaceOp: { op: 'replace', start: this.#seq, end: this.#seq } }
62
+ )
63
+ : this.#session.append(
64
+ 'fancy/status',
65
+ { content: [{ type: 'text', text }], source: { kind: 'user' } },
66
+ { surfaceOp: 'append' }
67
+ );
68
+ this.#seq ??= event.seq;
69
+ }
70
+
71
+ clear() { this.update(''); }
72
+ }
73
+
34
74
  // --------------------------------------------------------------------------
35
75
  // llmFollowup — hand a prompt to the LLM as a user message
36
76
  // --------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {