diff --git a/website/app/vt/cub/page.mdx b/website/app/vt/cub/page.mdx index 9db2fca69..bf7e08266 100644 --- a/website/app/vt/cub/page.mdx +++ b/website/app/vt/cub/page.mdx @@ -2,6 +2,6 @@ import VTSequence from "@/components/VTSequence"; # Cursor Backword (CUB) - + TODO diff --git a/website/components/VTSequence.tsx b/website/components/VTSequence.tsx index ee7f9bd7d..5262e4494 100644 --- a/website/components/VTSequence.tsx +++ b/website/components/VTSequence.tsx @@ -1,21 +1,43 @@ // Draw a diagram showing the VT sequence. +// +// There are some special sequence elements that can be used: +// +// - CSI will be replaced with ESC [. +// - Pn will be considered a parameter +// export default function VTSequence({ sequence, }: { sequence: string | [string]; }) { - // TODO: handle sequence array - const elem = typeof sequence === "string" ? sequence : sequence[0]; + let arr: [string] = typeof sequence === "string" ? [sequence] : sequence; - const specialChar = special[elem] ?? 0; - const hex = specialChar.toString(16).padStart(2, "0"); + if (arr[0] === "CSI") { + arr.shift(); + arr.unshift("ESC", "["); + } return (
-
-
0x{hex}
-
{sequence}
-
+ {arr.map((elem, i) => ( +
+ +
+ ))} +
+ ); +} + +function VTElem({ elem }: { elem: string }) { + const param = elem === "Pn"; + elem = param ? elem[1] : elem; + const specialChar = special[elem] ?? elem.charCodeAt(0); + const hex = specialChar.toString(16).padStart(2, "0").toUpperCase(); + + return ( +
+
0x{hex}
+
{elem}
); } @@ -23,4 +45,5 @@ export default function VTSequence({ const special: { [key: string]: number } = { BEL: 0x07, BS: 0x08, + ESC: 0x1b, };