@kaynooo/cli-forgejo 0.25.0 → 0.26.0

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.
Files changed (2) hide show
  1. package/dist/cli.js +72 -18
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -334,19 +334,53 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
334
334
  }
335
335
 
336
336
  // ../kit/src/theme.ts
337
+ function toLinear(channel) {
338
+ const value = channel / 255;
339
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
340
+ }
341
+ var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
342
+ function toOklab(hex) {
343
+ const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
344
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
345
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
346
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
347
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
348
+ }
349
+ function fromOklab([lightness, a, b]) {
350
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
351
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
352
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
353
+ const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
354
+ return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
355
+ }
356
+ var ENDS = new Map;
357
+ function gradientAt(theme, ratio) {
358
+ if (theme.gradient === undefined)
359
+ return;
360
+ const key = theme.gradient.join();
361
+ let ends = ENDS.get(key);
362
+ if (ends === undefined) {
363
+ ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
364
+ ENDS.set(key, ends);
365
+ }
366
+ const at = Math.min(1, Math.max(0, ratio));
367
+ const [from, to] = ends;
368
+ return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
369
+ }
337
370
  var DEFAULT = {
338
371
  colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
339
- glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
372
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
340
373
  accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
341
- bins: {}
374
+ bins: {},
375
+ gradient: ["#c084fc", "#67e8f9"]
342
376
  };
343
377
  var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
344
378
  var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
345
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
379
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
346
380
  var PRESETS = {
347
381
  default: {},
348
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
349
- mono: { colors: MONO, accents: ["bold"] },
382
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
383
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
350
384
  ascii: { glyphs: ASCII }
351
385
  };
352
386
  var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
@@ -384,6 +418,9 @@ function tinted(colors, spec, env = process5.env) {
384
418
  return chain[token] ?? chain;
385
419
  }, colors);
386
420
  }
421
+ function shaded(theme, colors, glyph, cells, width, env = process5.env) {
422
+ return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
423
+ }
387
424
  function isRecord(value) {
388
425
  return typeof value === "object" && value !== null && !Array.isArray(value);
389
426
  }
@@ -417,6 +454,8 @@ function applyPreset(theme, name, warn, where) {
417
454
  Object.assign(theme.glyphs, preset.glyphs);
418
455
  if (preset.accents !== undefined)
419
456
  theme.accents = [...preset.accents];
457
+ if (Object.hasOwn(preset, "gradient"))
458
+ theme.gradient = preset.gradient;
420
459
  return name;
421
460
  }
422
461
  function applyFile(theme, file, where, warn) {
@@ -444,6 +483,12 @@ function applyFile(theme, file, where, warn) {
444
483
  theme.accents = [...file.accents];
445
484
  else if (file.accents !== undefined)
446
485
  warn(`${where}: accents must be a non-empty list of colours`);
486
+ if (file.gradient === null)
487
+ theme.gradient = undefined;
488
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
489
+ theme.gradient = [file.gradient[0], file.gradient[1]];
490
+ else if (file.gradient !== undefined)
491
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
447
492
  if (isRecord(file.bins)) {
448
493
  for (const [bin, value] of Object.entries(file.bins)) {
449
494
  if (isColorSpec(value))
@@ -467,7 +512,7 @@ function isPath(chosen) {
467
512
  return chosen.includes("/") || chosen.endsWith(".json");
468
513
  }
469
514
  function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
470
- const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
515
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
471
516
  const sources = [];
472
517
  const chosen = env.KIT_THEME ?? "";
473
518
  const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
@@ -1015,7 +1060,7 @@ function bar(ratio, { width = 20, stream = process11.stdout, env = process11.env
1015
1060
  if (!takesControlCodes(stream, env))
1016
1061
  return `${FILLED.repeat(filled)}${EMPTY.repeat(width - filled)}`;
1017
1062
  const { theme } = activeTheme();
1018
- return `${tinted(colors, theme.colors.accent, env)(theme.glyphs.bar.repeat(filled))}${colors.dim(theme.glyphs.bar.repeat(width - filled))}`;
1063
+ return `${shaded(theme, colors, theme.glyphs.bar, filled, width, env)}${colors.dim(theme.glyphs.bar.repeat(width - filled))}`;
1019
1064
  }
1020
1065
  // ../kit/src/progress.ts
1021
1066
  import process13 from "process";
@@ -1427,6 +1472,13 @@ async function waitForCi(wait) {
1427
1472
  region?.stop();
1428
1473
  }
1429
1474
  }
1475
+ function ciLine(status, subject, details, out) {
1476
+ const rest = details.filter((each) => each !== undefined && each !== "").join(" ");
1477
+ return `${badge(status, out)} ${subject}${rest === "" ? "" : ` ${paint(out).dim(rest)}`}`;
1478
+ }
1479
+ function ciHeader(spinner, label, startedAt, out) {
1480
+ return `${spinner} ${label} ${paint(out).dim(formatElapsed(Date.now() - startedAt))}`;
1481
+ }
1430
1482
  // ../kit/src/cli.ts
1431
1483
  import { readFileSync as readFileSync2, realpathSync } from "fs";
1432
1484
  import { dirname as dirname3, join as join5 } from "path";
@@ -2806,6 +2858,15 @@ function startedAt(run) {
2806
2858
  const at = Date.parse(run.started);
2807
2859
  return Number.isNaN(at) || at < EPOCH ? undefined : at;
2808
2860
  }
2861
+ function elapsed(run, seen) {
2862
+ if (FINISHED.has(run.status))
2863
+ return run.duration > 0 ? `in ${formatSeconds(runSeconds(run))}` : undefined;
2864
+ const seconds = Math.floor((Date.now() - (startedAt(run) ?? seen)) / 1000);
2865
+ return seconds > 0 ? `for ${formatSeconds(seconds)}` : undefined;
2866
+ }
2867
+ function runLine(run, out, seen = Date.now()) {
2868
+ return ciLine(run.status, run.workflow_id, [`run ${run.id}`, `on ${run.prettyref}`, elapsed(run, seen)], out);
2869
+ }
2809
2870
  function startedAge(run, now = Date.now()) {
2810
2871
  return startedAt(run) === undefined ? "-" : formatAge(run.started, now);
2811
2872
  }
@@ -2990,7 +3051,6 @@ async function ci2(args) {
2990
3051
  return;
2991
3052
  }
2992
3053
  const json = values.json === true;
2993
- const { dim } = paint(process23.stderr);
2994
3054
  const runs = await waitForCi({
2995
3055
  tool: "ft ci",
2996
3056
  short,
@@ -3014,8 +3074,8 @@ async function ci2(args) {
3014
3074
  return stall === undefined ? undefined : { message: `runs queued on ${short} are not moving: ${stall.reason}`, certain: stall.certain };
3015
3075
  },
3016
3076
  lines: (spinner, found, started) => [
3017
- `${spinner} CI on ${short} ${dim(formatElapsed(Date.now() - started))}`,
3018
- ...(found ?? []).map((run) => ` ${badge(run.status, process23.stderr)} ${run.workflow_id} ${dim(`run ${run.id}`)}`)
3077
+ ciHeader(spinner, `CI on ${short}`, started, process23.stderr),
3078
+ ...(found ?? []).map((run) => ` ${runLine(run, process23.stderr)}`)
3019
3079
  ]
3020
3080
  });
3021
3081
  const status = overall(runs);
@@ -4019,8 +4079,8 @@ async function followRuns(pick, timeout, repo, idle, out = process.stdout, mode
4019
4079
  const started = Date.now();
4020
4080
  const latest = new Map;
4021
4081
  const seen = new Map;
4022
- const line = (run) => `${run.workflow_id} run ${run.id} on ${run.prettyref}: ${badge(run.status, out)}${elapsed(run, seen.get(run.id) ?? Date.now())}`;
4023
- const region = takesControlCodes(out) && !quiet ? liveRegion(() => [...latest.values()].map(line), out) : undefined;
4082
+ const line = (run) => runLine(run, out, seen.get(run.id) ?? Date.now());
4083
+ const region = takesControlCodes(out) && !quiet ? liveRegion((spinner) => [ciHeader(spinner, "CI", started, out), ...[...latest.values()].map((run) => ` ${line(run)}`)], out) : undefined;
4024
4084
  const followed = new Set;
4025
4085
  const failed = new Set;
4026
4086
  const failedJobs = [];
@@ -4103,12 +4163,6 @@ ${run.html_url}`);
4103
4163
  }
4104
4164
  }
4105
4165
  }
4106
- function elapsed(run, seen) {
4107
- if (FINISHED.has(run.status))
4108
- return run.duration > 0 ? ` in ${formatSeconds(runSeconds(run))}` : "";
4109
- const seconds = Math.floor((Date.now() - (startedAt(run) ?? seen)) / 1000);
4110
- return seconds > 0 ? ` for ${formatSeconds(seconds)}` : "";
4111
- }
4112
4166
  async function watch2(args) {
4113
4167
  const parsed = parse(args, usage5, options5);
4114
4168
  const { values } = parsed;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.25.0",
4
+ "version": "0.26.0",
5
5
  "description": "ft: Forgejo CI runs, logs, releases and issue checklists from the terminal, through tea.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -28,6 +28,6 @@
28
28
  "ft": "$npm_execpath src/cli.ts"
29
29
  },
30
30
  "devDependencies": {
31
- "@kaynooo/cli-kit": "0.29.0"
31
+ "@kaynooo/cli-kit": "0.33.0"
32
32
  }
33
33
  }