@boy-offi9-inc/tidepull 0.4.1 → 0.4.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/README.md CHANGED
@@ -164,6 +164,8 @@ TIDEPULL_THEME=high-contrast tidepull URL # --theme still wins if you also
164
164
 
165
165
  A theme only decides *which* codes are emitted: `--no-color`, `NO_COLOR` and a non-TTY stderr still strip every escape sequence, so redirected output and CI logs stay plain text.
166
166
 
167
+ On an interactive terminal the CLI shows a launch banner and a spinner while resolving a URL; quiet, JSON, `-g`, simulate and non-TTY modes suppress both so piped output stays data-only.
168
+
167
169
  From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node >= 22.18); `npm run build` emits JS + `.d.ts`.
168
170
 
169
171
  ## Capabilities and limits
package/dist/main.js CHANGED
@@ -13,7 +13,9 @@ import { defaultPluginDir, loadPlugins } from "./loader.js";
13
13
  import { table, fmtBytes } from "./ui/format.js";
14
14
  import { Logger, shouldUseColor } from "./ui/log.js";
15
15
  import { humanRenderer, jsonRenderer } from "./ui/render.js";
16
+ import { renderBanner } from "./ui/banner.js";
16
17
  import { pickTheme, THEME_NAMES } from "./ui/theme.js";
18
+ import { Spinner } from "./ui/spinner.js";
17
19
  /** Package version, read from package.json. */
18
20
  export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
19
21
  const HELP = `tidepull ${VERSION}: a minimal media downloader
@@ -177,6 +179,12 @@ export async function main(argv) {
177
179
  process.stderr.write(`ERROR: ${errMsg(e)}\n`);
178
180
  return 2;
179
181
  }
182
+ // Banner: interactive terminals only. Anything machine-facing (quiet, json,
183
+ // get-url, simulate, progress-json) or non-TTY stdout suppresses it.
184
+ const machineMode = values.quiet || values["dump-json"] || values["get-url"] || values.simulate || values["progress-json"];
185
+ if (process.stdout.isTTY && !machineMode) {
186
+ process.stderr.write(renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor()) + "\n");
187
+ }
180
188
  const log = new Logger({
181
189
  quiet: values.quiet,
182
190
  verbose: values.verbose,
@@ -272,6 +280,14 @@ export async function main(argv) {
272
280
  process.stderr.write(e.stack + "\n");
273
281
  code = Math.max(code, e instanceof TidepullError ? e.exitCode : 1);
274
282
  };
283
+ // Spinner for the resolve/extract phase: TTY stderr only, machine modes never see it.
284
+ const interactive = process.stdout.isTTY && !machineMode && !values["no-progress"];
285
+ const spinner = new Spinner({ text: "extracting…", env: process.env });
286
+ const spin = () => {
287
+ if (interactive)
288
+ spinner.start();
289
+ };
290
+ const stopSpin = (final) => spinner.stop(final);
275
291
  /** What to do with one extracted item: print info, list formats, print URLs, or download it. */
276
292
  const handle = async (info, fields) => {
277
293
  if (values["dump-json"])
@@ -303,8 +319,10 @@ export async function main(argv) {
303
319
  try {
304
320
  for (const url of urls) {
305
321
  try {
322
+ spin();
306
323
  const resolved = await tp.resolve(url, { signal: ctl.signal });
307
324
  if (isPlaylist(resolved) && (values["dump-json"] || values["list-formats"])) {
325
+ stopSpin(`${resolved.title}: ${resolved.entries.length} item(s)`);
308
326
  // listing a playlist needs no request per entry
309
327
  if (values["dump-json"])
310
328
  process.stdout.write(JSON.stringify(resolved) + "\n");
@@ -315,6 +333,7 @@ export async function main(argv) {
315
333
  continue;
316
334
  }
317
335
  for await (const item of resolveItems(tp, resolved, { signal: ctl.signal, items: values["playlist-items"] })) {
336
+ stopSpin();
318
337
  try {
319
338
  if (item.error)
320
339
  throw item.error;
@@ -328,6 +347,7 @@ export async function main(argv) {
328
347
  }
329
348
  }
330
349
  catch (e) {
350
+ stopSpin();
331
351
  if (ctl.signal.aborted) {
332
352
  process.stderr.write("\n");
333
353
  log.error("Interrupted by user (partial files kept, re-run to resume)");
@@ -341,6 +361,7 @@ export async function main(argv) {
341
361
  }
342
362
  }
343
363
  finally {
364
+ stopSpin();
344
365
  process.removeListener("SIGINT", onSigint);
345
366
  }
346
367
  return code;
@@ -0,0 +1,3 @@
1
+ import type { Theme } from "./theme.js";
2
+ /** Launch banner for interactive terminals; version dimmed beside the logo. */
3
+ export declare function renderBanner(version: string, theme: Theme, color?: boolean): string;
@@ -0,0 +1,28 @@
1
+ const GLYPHS = {
2
+ t: ["| |_ ", "| __|", "| |_ ", " \\__|"],
3
+ i: ["|_ _|", " | | ", " | | ", "|___|"],
4
+ d: [" __| |", " / _` |", "| (_| |", " \\__,_|"],
5
+ e: [" ___ ", " / _ \\", "| __/", " \\___|"],
6
+ p: ["| '_ \\ ", "| |_) |", "| .__/ ", "|_| "],
7
+ u: ["| | ", "| | ", "| | ", "|_| "],
8
+ l: ["| |", "| |", "| |", "|_|"],
9
+ };
10
+ /** Block-letter logo, assembled row by row so the letters are correct by construction. */
11
+ function logo() {
12
+ const rows = ["", "", "", ""];
13
+ for (const ch of "tidepull") {
14
+ const g = GLYPHS[ch];
15
+ for (let r = 0; r < 4; r++)
16
+ rows[r] += g[r] + (r === 0 && ch !== "l" ? " " : " ");
17
+ }
18
+ return rows.map((r) => r.trimEnd());
19
+ }
20
+ /** Launch banner for interactive terminals; version dimmed beside the logo. */
21
+ export function renderBanner(version, theme, color = true) {
22
+ const plain = !color || !!process.env.NO_COLOR || theme.name === "mono";
23
+ const paint = (c, s) => (plain ? s : c + s + theme.reset);
24
+ const dim = (s) => (plain ? s : theme.dim + s + theme.reset);
25
+ const rows = logo();
26
+ rows[3] = paint(theme.accent, rows[3]) + " " + dim(`v${version}`);
27
+ return rows.map((r, i) => (i === 3 ? r : paint(theme.accent, r))).join("\n");
28
+ }
@@ -0,0 +1,24 @@
1
+ export interface SpinnerOptions {
2
+ text?: string;
3
+ stream?: NodeJS.WriteStream;
4
+ env?: NodeJS.ProcessEnv;
5
+ interval?: number;
6
+ }
7
+ /**
8
+ * Single-line activity spinner on stderr. Never touches stdout, and never
9
+ * starts at all when stderr is not a TTY or CI is detected: machine modes
10
+ * must see zero bytes from it.
11
+ */
12
+ export declare class Spinner {
13
+ private timer;
14
+ private frame;
15
+ private text;
16
+ private readonly stream;
17
+ private readonly env;
18
+ private readonly interval;
19
+ constructor(o?: SpinnerOptions);
20
+ get active(): boolean;
21
+ start(): this;
22
+ stop(finalLine?: string): this;
23
+ private render;
24
+ }
@@ -0,0 +1,49 @@
1
+ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧"];
2
+ /**
3
+ * Single-line activity spinner on stderr. Never touches stdout, and never
4
+ * starts at all when stderr is not a TTY or CI is detected: machine modes
5
+ * must see zero bytes from it.
6
+ */
7
+ export class Spinner {
8
+ timer;
9
+ frame = 0;
10
+ text;
11
+ stream;
12
+ env;
13
+ interval;
14
+ constructor(o = {}) {
15
+ this.text = o.text ?? "extracting…";
16
+ this.stream = o.stream ?? process.stderr;
17
+ this.env = o.env ?? process.env;
18
+ this.interval = o.interval ?? 80;
19
+ }
20
+ get active() {
21
+ return this.timer !== undefined;
22
+ }
23
+ start() {
24
+ if (this.timer || !this.stream.isTTY || this.env.CI)
25
+ return this;
26
+ this.render();
27
+ this.timer = setInterval(() => {
28
+ this.frame = (this.frame + 1) % FRAMES.length;
29
+ this.render();
30
+ }, this.interval);
31
+ this.timer.unref();
32
+ return this;
33
+ }
34
+ stop(finalLine) {
35
+ if (!this.timer)
36
+ return this;
37
+ clearInterval(this.timer);
38
+ this.timer = undefined;
39
+ this.stream.write(`\r\x1b[K`);
40
+ if (finalLine) {
41
+ const dim = this.env.NO_COLOR ? "" : "\x1b[2m";
42
+ this.stream.write(`${dim}${finalLine}\x1b[0m\n`);
43
+ }
44
+ return this;
45
+ }
46
+ render() {
47
+ this.stream.write(`\r\x1b[K${FRAMES[this.frame]} ${this.text}`);
48
+ }
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A minimal, from-scratch media downloader library: extractor plugins, yt-dlp-style format selection, resumable downloads.",
5
5
  "type": "module",
6
6
  "license": "MIT",