// A shell line a reader runs next: a refusal's `next`, a clone URL, the // install line. The terminal is where work happens, so every page that // suggests an action shows its command, whole and copyable, never a form. // // A page marks its main commands `numbered`: while the single keys are on, // each shows its number before the `$`, and that number key copies it // ("Copy (1)" in the button's title). import { Check, Copy } from "lucide-react"; import { Button } from "../../components/ui/button.tsx"; import { useCopy } from "./copy-action.tsx"; import { useNumberedCommand } from "./keys.tsx"; /** How far a line of the command hangs, in ch, when the column breaks it. */ const HANG = 6; /** * A line's hang: 6ch, or less on a line so short that its longest word * would not fit beside the hang. The box hugs its longest line, so a line's * room beside its hang is its own length less the hang; a word wider than * that room is broken in two (` today` read "tod" / " ay"). Such a * line fits whole wherever its box does, so its hang never shows. */ const hangOf = (words: readonly string[], line: string) => Math.min( HANG, line.length - Math.max(0, ...words.map(({ length }) => length)) ); // The command's words, each kept whole on its line: a narrow column breaks // the line between words, never after a word's own hyphen // (`lint-heading-levels`, `--project`) nor before a closing ` \`; a word // longer than the line (a URL) still breaks, anywhere. Each of the // command's own lines hangs, so a line the column breaks reads as one line // going on. The text is the command's, space for space. const wordsOf = (command: string) => command.split("\n").map((line, at, lines) => { const parts = line.split(/(?\s+)(?!\\$)/u); const hang = hangOf( parts.filter((part) => part.trim() !== ""), line ); return ( // A line never moves: its place in the command is its key. {parts.map((part, index) => part.trim() === "" ? ( part ) : ( {part} ) )} {at < lines.length - 1 ? "\n" : null} ); }); const Line = ({ command, number, }: { readonly command: string; readonly number: number | undefined; }) => { const { copied, copy } = useCopy(command); return (
{number === undefined ? null : ( )} {wordsOf(command)}
); }; const NumberedLine = ({ command }: { readonly command: string }) => ( ); export const CommandLine = ({ command, numbered = false, }: { readonly command: string; /** One of the page's main commands, which a number key copies. */ readonly numbered?: boolean; }) => numbered ? ( ) : ( );