[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

test: failing repro for percent-sizing

Nate Moore (Jun 4, 2026, 12:33 AM -0500) 5b5d80bc d75fb4b6

+55
+55
test/percent-sizing.test.ts
··· 1 + import { beforeEach, describe, expect, it } from "./suite.ts"; 2 + import { createTerm, type Term } from "../term.ts"; 3 + import { close, fit, fixed, open, percent, text } from "../ops.ts"; 4 + 5 + describe("percent min/max sizing", () => { 6 + let term: Term; 7 + 8 + beforeEach(async () => { 9 + term = await createTerm({ width: 20, height: 12 }); 10 + }); 11 + 12 + it("fit(min = percent(0.5)) grows a short child to 50% of the parent", () => { 13 + let r = term.render([ 14 + open("parent", { layout: { height: fixed(12), direction: "ttb" } }), 15 + open("child", { 16 + layout: { height: fit(percent(0.5) as unknown as number) }, 17 + }), 18 + text("A"), 19 + close(), 20 + close(), 21 + ]); 22 + // pins: a 1-line fit child is floored to 50% of the 12-row parent 23 + expect(r.info.get("child")!.bounds.height).toBe(6); 24 + }); 25 + 26 + it("fit(min = percent(0.5)) is a floor, not a fixed cap", () => { 27 + let r = term.render([ 28 + open("parent", { layout: { height: fixed(12), direction: "ttb" } }), 29 + open("child", { 30 + layout: { height: fit(percent(0.5) as unknown as number) }, 31 + }), 32 + text("A\nA\nA\nA\nA\nA\nA\nA"), 33 + close(), 34 + close(), 35 + ]); 36 + // pins: content taller than 50% is allowed past the floor, not pinned to 6 37 + expect(r.info.get("child")!.bounds.height).toBe(8); 38 + }); 39 + 40 + it("fit(0, max = percent(0.5)) clamps a tall child down to 50%", () => { 41 + let r = term.render([ 42 + open("parent", { layout: { height: fixed(12), direction: "ttb" } }), 43 + open("child", { 44 + layout: { height: fit(0, percent(0.5) as unknown as number) }, 45 + }), 46 + open("inner", { layout: { height: fixed(12) } }), 47 + text("A"), 48 + close(), 49 + close(), 50 + close(), 51 + ]); 52 + // pins: a 12-row inner is clamped down to 50% (6) of the parent 53 + expect(r.info.get("child")!.bounds.height).toBe(6); 54 + }); 55 + });