Add OSC 8 hyperlinks to root-help header#24
Merged
kjanat merged 2 commits intoJun 10, 2026
Conversation
Closes #20. The root-help header (`name vX.Y.Z`) can now carry clickable OSC 8 hyperlinks: the name links to the repo/homepage and the version to the release tag. Both blockers from the issue are addressed: - New `.links({ name?, version? })` builder method stores header-only link targets, so the linked name never leaks into usage lines, the `--help` hint, binName, the commands table, or completion scripts. Called without arguments, URLs are derived from package.json metadata when `.packageJson()` is active (discovery and pre-loaded data forms): name → normalized `repository` URL (fallback `homepage`), version → forge release tag (GitHub `/releases/tag/v{v}`, GitLab `/-/releases/v{v}`). Escapes are gated on TTY detection and overridable via the new `help.hyperlinks` option. - Width helpers are now ANSI/OSC-aware: shared `padEnd()`/`wrapText()` in `help/ansi.ts` measure with `visibleWidth()` (strips CSI + OSC escapes), replacing the duplicated `.length`-based copies in `help/index.ts` and `root-help.ts`. Also exported: `osc8(url, text)`, `visibleWidth(text)`, and `packageRepositoryUrl(pkg)` (normalizes git+/scp/shorthand repository locators to browsable https URLs); package.json parsing now extracts `homepage` and `repository`.
This comment was marked as outdated.
This comment was marked as outdated.
commit: |
6d0fad0 to
c453898
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for OSC 8 hyperlinks in the root-help header, allowing the program name and version to become clickable links in supporting terminals. Links can be explicitly configured via
.links()or automatically derived from package.json metadata (repository/homepage).Key Changes
.links()builder method — Configure explicit hyperlink URLs for the program name and version in root help output.packageJson()is active, missing link URLs are derived from:repositoryfield → normalized to browsable HTTPS URL (supports GitHub, GitLab, Bitbucket shorthands and various formats)homepagefield → fallback for the name link/releases/tag/v{version}, GitLab:/-/releases/v{version})ansi.tsmodule with:osc8(url, text)— Wrap text in OSC 8 hyperlink escape sequencesvisibleWidth(text)— Measure text width ignoring escape sequencesstripAnsi(text)— Remove ANSI CSI and OSC escapespadEnd()andwrapText()— Escape-aware padding and wrapping for aligned help outputhelp.hyperlinksoption); escapes never leak into piped output or non-header sectionsPackageJsonDatato includehomepageandrepositoryfields with support for both string and object formspackageRepositoryUrl()export — Public utility to normalize repository locators to browsable HTTPS URLsImplementation Details
--versionflag output stays plain (no escapes).run()) or directly from pre-loaded data (.execute())