Skip to content

Commit 875143c

Browse files
committed
Set the landing's two doors as a pair
The key and its description were joined by a single space, so the two lines started their descriptions on different columns and read as two unrelated notes rather than as the set they are. A fixed key column lines them up. The version moves a row away from them for the same reason: sitting flush under the two keys it read as a third door, when it is only a statement of what is running.
1 parent 5a76641 commit 875143c

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/tui-opentui/landing.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,18 @@ describe("landing screen", () => {
150150
mark.length,
151151
)
152152
expect(painted.indexOf(mark.at(-1) as string)).toBeLessThan(top)
153-
// The two doors sit beside the mark, not under it.
153+
// The two doors sit beside the mark, not under it, and their
154+
// descriptions share one column — ragged, the pair reads as two
155+
// unrelated lines rather than as a set.
156+
const descriptionColumns = new Set<number>()
154157
for (const hint of LANDING_HINTS) {
155158
const row = painted.find((line) => line.includes(hint.rest))
156159
expect(row).toBeDefined()
157160
expect(row).toContain(hint.key)
158161
expect(row!.indexOf(hint.key)).toBeGreaterThan(0)
162+
descriptionColumns.add(row!.indexOf(hint.rest))
159163
}
164+
expect(descriptionColumns.size).toBe(1)
160165
// The version sits with the hints, and cannot drift from package.json.
161166
expect(LANDING_VERSION).toBe(`v${pkg.version}`)
162167
expect(h.captureCharFrame()).toContain(LANDING_VERSION)

src/tui-opentui/landing.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,25 @@ export const LANDING_HINTS: readonly {
6565
{ key: "?", rest: "for shortcuts" },
6666
]
6767

68+
/**
69+
* Columns held for the key, so the descriptions beside them start on one
70+
* column. Ragged, the pair reads as two unrelated lines rather than as a set.
71+
*/
72+
export const LANDING_KEY_WIDTH = LANDING_HINTS.reduce(
73+
(widest, hint) => Math.max(widest, hint.key.length),
74+
0,
75+
)
76+
77+
/** Air between the key column and the description it labels. */
78+
const LANDING_KEY_GAP = 2
79+
6880
/** Columns the hint block needs, its longest line deciding. */
6981
export const LANDING_HINT_WIDTH = Math.max(
70-
LANDING_HINTS.reduce((widest, hint) => Math.max(widest, hint.key.length + 1 + hint.rest.length), 0),
82+
LANDING_HINTS.reduce(
83+
(widest, hint) =>
84+
Math.max(widest, LANDING_KEY_WIDTH + LANDING_KEY_GAP + hint.rest.length),
85+
0,
86+
),
7187
LANDING_VERSION.length,
7288
)
7389

@@ -336,17 +352,30 @@ function createHintBlock(ctx: CliRenderer): BoxRenderable {
336352
backgroundColor: UI.ground,
337353
})
338354
LANDING_HINTS.forEach((hint, index) => {
355+
const gap = " ".repeat(
356+
LANDING_KEY_WIDTH - hint.key.length + LANDING_KEY_GAP,
357+
)
339358
block.add(
340359
new TextRenderable(ctx, {
341360
id: `shell-landing-hint-${index}`,
342361
height: 1,
343362
content: new StyledText([
344363
fgChunk(UI.text)(hint.key),
345-
fgChunk(UI.textDim)(` ${hint.rest}`),
364+
fgChunk(UI.textDim)(`${gap}${hint.rest}`),
346365
]),
347366
}),
348367
)
349368
})
369+
// The build is a fact about what is running, not a third door. Flush against
370+
// the two keys it read as one of them.
371+
block.add(
372+
new TextRenderable(ctx, {
373+
id: "shell-landing-version-gap",
374+
height: 1,
375+
content: "",
376+
fg: UI.ground,
377+
}),
378+
)
350379
block.add(
351380
new TextRenderable(ctx, {
352381
id: "shell-landing-version",
@@ -364,7 +393,9 @@ function createHintBlock(ctx: CliRenderer): BoxRenderable {
364393
*/
365394
export function fitLandingMark(above: LandingAbove, grid: MarkGrid | null): void {
366395
above.grid = grid
367-
const rows = grid?.rows ?? LANDING_HINTS.length + 1
396+
// With no mark, the hero is exactly the hint block: the two keys, the blank
397+
// row, and the version.
398+
const rows = grid?.rows ?? LANDING_HINTS.length + 2
368399
above.hero.height = rows
369400
above.markColumn.visible = grid !== null
370401
above.markColumn.width = grid?.cols ?? 0

0 commit comments

Comments
 (0)