Download packages/pi-tui/src/components/v-stack.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/pi-tui/src/components/v-stack.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/pi-tui/src/components/v-stack.ts
-
curl -L -o v-stack.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/pi-tui/src/components/v-stack.ts
1.18 kB
| import { allocateStackSizes, Stack, type StackChild, type StackOptions, visibleStackEntries } from "./stack.ts"; | |
| export class VStack extends Stack { | |
| protected readonly layoutType = "vstack" as const; | |
| constructor(children: StackChild[] = [], options: StackOptions = {}) { | |
| super(children, options); | |
| } | |
| override render(width: number): string[] { | |
| const viewport = { width: Math.max(1, width), height: Number.MAX_SAFE_INTEGER }; | |
| const entries = visibleStackEntries(this.entries, viewport); | |
| const rendered = entries.map((entry) => entry.component.render(viewport.width)); | |
| const sizes = allocateStackSizes( | |
| entries, | |
| rendered.map((lines) => lines.length), | |
| undefined, | |
| this.gap, | |
| ); | |
| const lines: string[] = []; | |
| for (let index = 0; index < entries.length; index++) { | |
| if (index > 0) { | |
| for (let gap = 0; gap < this.gap; gap++) lines.push(""); | |
| } | |
| const childLines = rendered[index]!.slice(0, sizes[index]); | |
| lines.push(...childLines); | |
| for (let padding = childLines.length; padding < sizes[index]!; padding++) lines.push(""); | |
| } | |
| return lines; | |
| } | |
| } | |
| export type { StackChild, StackEntry, StackEntryOptions, StackOptions } from "./stack.ts"; | |