command.tsx
This file
Path
apps/web/src/features/shared/command.tsx
127 lines · 4.0 KiB · TypeScript
Last changed by
Merge build/1315-command-line into mainoscabrielbefore adoption252b871
History of this fileTake it
Fix the finish review's findings: drafted code draws, counts agree, commands hangoscabrielbefore adoptionf7f6e49
lines 1–7why, one step back1// A shell line a reader runs next: a refusal's `next`, a clone URL, the2// install line. The terminal is where work happens, so every page that3// suggests an action shows its command, whole and copyable, never a form.4//5// A page marks its main commands `numbered`: while the single keys are on,6// each shows its number before the `$`, and that number key copies it7// ("Copy (1)" in the button's title).Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 8–10why, one step back8import { Check, Copy } from "lucide-react";910import { Button } from "../../components/ui/button.tsx";Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
lines 11–12why, one step back11import { useCopy } from "./copy-action.tsx";12import { useNumberedCommand } from "./keys.tsx";Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
line 13why, one step back13Merge build/1315-command-line into mainoscabrielbefore adoption252b871
lines 14–29why, one step back14/** How far a line of the command hangs, in ch, when the column breaks it. */15const HANG = 6;1617/**18 * A line's hang: 6ch, or less on a line so short that its longest word19 * would not fit beside the hang. The box hugs its longest line, so a line's20 * room beside its hang is its own length less the hang; a word wider than21 * that room is broken in two (`<cli> today` read "tod" / "<cli> ay"). Such a22 * line fits whole wherever its box does, so its hang never shows.23 */24const hangOf = (words: readonly string[], line: string) =>25 Math.min(26 HANG,27 line.length - Math.max(0, ...words.map(({ length }) => length))28 );29Finish the Control room: every page passes axe and a keyboard walk in both schemesoscabrielbefore adoption3fd50a5
lines 30–31why, one step back30// The command's words, each kept whole on its line: a narrow column breaks31// the line between words, never after a word's own hyphenFix the finish review's findings: drafted code draws, counts agree, commands hangoscabrielbefore adoptionf7f6e49
lines 32–35why, one step back32// (`lint-heading-levels`, `--project`) nor before a closing ` \`; a word33// longer than the line (a URL) still breaks, anywhere. Each of the34// command's own lines hangs, so a line the column breaks reads as one line35// going on. The text is the command's, space for space.Finish the Control room: every page passes axe and a keyboard walk in both schemesoscabrielbefore adoption3fd50a5
line 36why, one step back36const wordsOf = (command: string) =>Merge build/1315-command-line into mainoscabrielbefore adoption252b871
lines 37–67why, one step back37 command.split("\n").map((line, at, lines) => {38 const parts = line.split(/(?<space>\s+)(?!\\$)/u);3940 const hang = hangOf(41 parts.filter((part) => part.trim() !== ""),42 line43 );4445 return (46 // A line never moves: its place in the command is its key.47 <span48 className="block"49 key={at}50 style={{ paddingLeft: `${hang}ch`, textIndent: `-${hang}ch` }}51 >52 {parts.map((part, index) =>53 part.trim() === "" ? (54 part55 ) : (56 <span57 className="inline-block max-w-full indent-0 [overflow-wrap:anywhere]"58 key={index}59 >60 {part}61 </span>62 )63 )}64 {at < lines.length - 1 ? "\n" : null}65 </span>66 );67 });Finish the Control room: every page passes axe and a keyboard walk in both schemesoscabrielbefore adoption3fd50a5
line 68why, one step back68Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
lines 69–76why, one step back69const Line = ({70 command,71 number,72}: {73 readonly command: string;74 readonly number: number | undefined;75}) => {76 const { copied, copy } = useCopy(command);Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 77–78why, one step back7778 return (Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 79why, one step back79 <div className="border-rule bg-surface text-mono leading-terminal flex w-fit max-w-full min-w-0 items-start gap-2 border py-1 pr-1 pl-3 font-mono">Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
lines 80–87why, one step back80 {number === undefined ? null : (81 <span82 aria-hidden="true"83 className="text-muted-foreground font-sans tabular-nums select-none"84 >85 {number}86 </span>87 )}Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 88–90why, one step back88 <span aria-hidden="true" className="text-muted-foreground select-none">89 $90 </span>Finish the Control room: every page passes axe and a keyboard walk in both schemesoscabrielbefore adoption3fd50a5
lines 91–92why, one step back91 <code className="min-w-0 flex-1 py-0.5 whitespace-pre-wrap select-all">92 {wordsOf(command)}Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 93–97why, one step back93 </code>94 <Button95 className="shrink-0 font-sans"96 onClick={copy}97 size="sm"Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
line 98why, one step back98 title={number === undefined ? undefined : `Copy (${number})`}Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 99–102why, one step back99 type="button"100 variant="ghost"101 >102 {copied ? <Check aria-hidden="true" /> : <Copy aria-hidden="true" />}Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
line 103why, one step back103 <span className="sr-only sm:not-sr-only @max-xs:sr-only">Give the web one shell and one look: shared views for refusals, credit trailers, posture, outcomes and stages, on shadcn base-lyra tokens, with PRODUCT.md and DESIGN.mdoscabrielbefore adoptioneebd79b
lines 104–109why, one step back104 {copied ? "Copied" : "Copy"}105 </span>106 </Button>107 </div>108 );109};Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726
lines 110–127why, one step back110111const NumberedLine = ({ command }: { readonly command: string }) => (112 <Line command={command} number={useNumberedCommand(command)} />113);114115export const CommandLine = ({116 command,117 numbered = false,118}: {119 readonly command: string;120 /** One of the page's main commands, which a number key copies. */121 readonly numbered?: boolean;122}) =>123 numbered ? (124 <NumberedLine command={command} />125 ) : (126 <Line command={command} number={undefined} />127 );