-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e9a502
commit 526aa6b
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
import { log } from '@stacksjs/logging' | ||
import ansiEscapes from 'ansi-escapes' | ||
import prompts from 'prompts' | ||
import supportsHyperlinks from 'supports-hyperlinks' | ||
|
||
export { log, prompts } | ||
|
||
// thanks to https://github.com/sindresorhus/terminal-link/blob/main/index.js | ||
// eslint-disable-next-line ts/no-unsafe-function-type | ||
export default function terminalLink(text: string, url: string, { target = 'stdout', ...options }: { target?: string, fallback?: boolean | Function }): string { | ||
// @ts-expect-error - it is not properly typed | ||
if (!supportsHyperlinks[target]) { | ||
// If the fallback has been explicitly disabled, don't modify the text itself. | ||
if (options.fallback === false) { | ||
return text | ||
} | ||
|
||
return typeof options.fallback === 'function' ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)` | ||
} | ||
|
||
return ansiEscapes.link(text, url) | ||
} |