@narumitw/pi-statusline 0.8.0 → 0.9.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/package.json +1 -1
  2. package/src/statusline.ts +24 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-statusline",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Pi extension that replaces the footer with an information-rich statusline.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/statusline.ts CHANGED
@@ -41,6 +41,7 @@ interface TokenTotals {
41
41
  }
42
42
 
43
43
  const STATUSLINE_KEY = "statusline";
44
+ const GITHUB_PR_KEY = "github-pr";
44
45
  const SETTINGS_FILE = "pi-statusline-settings.json";
45
46
  const DEFAULT_PRESET: StatuslinePresetName = "tokyo-night";
46
47
 
@@ -276,8 +277,11 @@ function buildSegment(
276
277
  thinkingColor(runtime.thinkingLevel),
277
278
  "header",
278
279
  );
279
- case "branch":
280
- return segment(name, `🌿 ${footerData.getGitBranch() ?? "no-git"}`, color, "git");
280
+ case "branch": {
281
+ const branch = footerData.getGitBranch();
282
+ const pr = branch ? prLinkFromStatuses(footerData.getExtensionStatuses()) : undefined;
283
+ return segment(name, pr ? `🌿 ${branch} (${pr})` : `🌿 ${branch ?? "no-git"}`, color, "git");
284
+ }
281
285
  case "cwd":
282
286
  return segment(name, `📁 ${basename(ctx.cwd) || ctx.cwd}`, color, "directory");
283
287
  case "tools":
@@ -373,6 +377,19 @@ export function formatToolActivity(runtime: RuntimeState): string {
373
377
  return "💤 idle";
374
378
  }
375
379
 
380
+ export function prLinkFromStatuses(statuses: ReadonlyMap<string, string>): string | undefined {
381
+ const value = statuses.get(GITHUB_PR_KEY);
382
+ if (!value) return undefined;
383
+ // Extract the OSC 8 hyperlink span (the clickable "#123"); skip non-PR states
384
+ // like "PR gh missing" that carry no link. github-pr emits exactly one link, so the
385
+ // first OSC 8 span is the PR number.
386
+ const open = value.indexOf("\x1b]8;;");
387
+ if (open === -1) return undefined;
388
+ const closeMarker = "\x1b]8;;\x07";
389
+ const close = value.indexOf(closeMarker, open + 1);
390
+ return close === -1 ? undefined : value.slice(open, close + closeMarker.length);
391
+ }
392
+
376
393
  function formatExtensionStatuses(
377
394
  statuses: ReadonlyMap<string, string>,
378
395
  theme: Theme,
@@ -383,7 +400,11 @@ function formatExtensionStatuses(
383
400
  const visibleStatuses = [
384
401
  ...formatDuplicateExtensionStatus(runtime, theme),
385
402
  ...[...statuses.entries()]
386
- .filter(([key, value]) => key !== STATUSLINE_KEY && value.trim().length > 0)
403
+ // github-pr is rendered inline in the branch segment, so skip it here to avoid duplication.
404
+ .filter(
405
+ ([key, value]) =>
406
+ key !== STATUSLINE_KEY && key !== GITHUB_PR_KEY && value.trim().length > 0,
407
+ )
387
408
  .map(([key, value]) => formatExtensionStatus(key, value, theme, config)),
388
409
  ].slice(0, 5);
389
410