🎥 Make videos programmatically with React
hyperlink feature for templates
Jonny Burgerba5ed3b21498
diff --git a/packages/create-video/src/hyperlinks/is-supported.ts b/packages/create-video/src/hyperlinks/is-supported.tsnew file mode 100644index 0000000000..edc0d8f468--- /dev/null+++ b/packages/create-video/src/hyperlinks/is-supported.ts@@ -0,0 +1,92 @@+// From https://github.com/jamestalmage/supports-hyperlinks/blob/master/index.js++// MIT License+// Copyright (c) James Talmage <[email protected]> (github.com/jamestalmage)+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:+// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.++function parseVersion(versionString: string) {+ if (/^\d{3,4}$/.test(versionString)) {+ // Env var doesn't always use dots. example: 4601 => 46.1.0+ const m = /(\d{1,2})(\d{2})/.exec(versionString) || [];+ return {+ major: 0,+ minor: parseInt(m[1] as string, 10),+ patch: parseInt(m[2] as string, 10),+ };+ }++ const versions = (versionString || '').split('.').map((n) => parseInt(n, 10));+ return {+ major: versions[0],+ minor: versions[1],+ patch: versions[2],+ };+}++export function supportsHyperlink(): false | string {+ const {+ CI,+ NETLIFY,+ TEAMCITY_VERSION,+ TERM_PROGRAM,+ TERM_PROGRAM_VERSION,+ VTE_VERSION,+ } = process.env;++ // Netlify does not run a TTY, it does not need `supportsColor` check+ if (NETLIFY) {+ return 'Click';+ }++ if (process.platform === 'win32') {+ return false;+ }++ if (CI) {+ return false;+ }++ if (TEAMCITY_VERSION) {+ return false;+ }++ if (TERM_PROGRAM) {+ const version = parseVersion(TERM_PROGRAM_VERSION || '');++ switch (TERM_PROGRAM) {+ case 'iTerm.app':+ if (version.major === 3) {+ return (version.minor as number) >= 1 ? 'Cmd+Click' : false;+ }++ return (version.major as number) > 3 ? 'Cmd+Click' : false;+ case 'WezTerm':+ return (version.major as number) >= 20200620 ? 'Click' : false;+ case 'vscode':+ // eslint-disable-next-line no-mixed-operators+ return (version.major as number) > 1 ||+ (version.major === 1 && (version.minor as number) >= 72)+ ? process.platform === 'darwin'+ ? 'Option+Click'+ : 'Ctrl+Click'+ : false;+ // No default+ }+ }++ if (VTE_VERSION) {+ // 0.50.0 was supposed to support hyperlinks, but throws a segfault+ if (VTE_VERSION === '0.50.0') {+ return false;+ }++ const version = parseVersion(VTE_VERSION);+ return (version.major as number) > 0 || (version.minor as number) >= 50+ ? 'Click'+ : false;+ }++ return false;+}diff --git a/packages/create-video/src/hyperlinks/make-link.ts b/packages/create-video/src/hyperlinks/make-link.tsnew file mode 100644index 0000000000..4398f1ed04--- /dev/null+++ b/packages/create-video/src/hyperlinks/make-link.ts@@ -0,0 +1,26 @@+import {supportsHyperlink} from './is-supported';++const OSC = '\u001B]';+const SEP = ';';+const BEL = '\u0007';++export const makeHyperlink = ({+ text,+ url,+ fallback,+}: {+ text: string | ((clickInstruction: string) => string);+ url: string;+ fallback: string;+}) => {+ const supports = supportsHyperlink();+ if (!supports) {+ return fallback;+ }++ const label = typeof text === 'function' ? text(supports) : text;++ return [OSC, '8', SEP, SEP, url, BEL, label, OSC, '8', SEP, SEP, BEL].join(+ '',+ );+};diff --git a/packages/create-video/src/select-template.ts b/packages/create-video/src/select-template.tsindex 5e09ba5903..ab7a854314 100644--- a/packages/create-video/src/select-template.ts+++ b/packages/create-video/src/select-template.ts@@ -1,5 +1,6 @@import chalk from 'chalk';import minimist from 'minimist';+import {makeHyperlink} from './hyperlinks/make-link';import prompts, {selectAsync} from './prompts';import {stripAnsi} from './strip-ansi';import type {Template} from './templates';@@ -43,8 +44,16 @@ export const selectTemplate = async () => {return {value: template,title:- chalk.bold(padEnd(template.shortName, descriptionColumn)) +- template.description.trim(),+ chalk.bold(+ padEnd(+ makeHyperlink({+ text: template.shortName,+ url: `https://remotion.dev/templates/${template.cliId}`,+ fallback: template.shortName,+ }),+ descriptionColumn,+ ),+ ) + template.description.trim(),};}),},