Draw hook-notices' and turn-nav's lines above the prompt as one row.

hook-notices and turn-nav each draw a line above the prompt. prompt-band puts both on one row, so they take one line instead of two:
🧭 Prompts · 9 · fix the… │ 🪝 Hook messages · 3 · ⚠ 1 · deploy ch…
On a narrow terminal the two stack again. Pressing either half does what the mod's own line does.
Needs hook-notices and turn-nav; it shows nothing on its own.
hooks/register.tsx 57 lines1import type { Register } from 'claude-code'
2import { cellWidth, fitRow, sharedWidths } from './band'
3
4// What hook-notices and turn-nav publish for this row; null when there is nothing to show.
5const HOOK = { plugin: 'hook-notices', key: 'chip' } as const
6const NAV = { plugin: 'turn-nav', key: 'chip' } as const
7
8// A press is answered by the mod whose line it is, in its ui.press hook: opened there,
9// inside the person's press, its pane is placed at any width. These handlers have
10// nothing left to do.
11const answeredByOwner = () => undefined
12
13export const register: Register = on => {
14 on('session.start', async ($, e, next) => {
15 // hook-notices and turn-nav read this and leave their own lines to this row.
16 // ponytail: no event tells a mod it unloads, so disabling this mod mid-session
17 // leaves both lines hidden until the session restarts.
18 await $.env.set('PROMPT_BAND', '1')
19 return next(e)
20 })
21
22 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
23 if (e.props.hasSurvey) return next(e)
24 const { value: hook } = await $.state.get(HOOK)
25 const { value: nav } = await $.state.get(NAV)
26 if (!hook && !nav) return next(e)
27 const { Box, Button, Text } = $.ui.resolve(e)
28 const below = await next(e)
29 // No hotkeys: a plain Button draws one as `h: ` ahead of the label.
30 const hookLine = (width: number) => hook && <Button key="hook-notices" plain dimColor label={fitRow(hook.label, width)} onPress={answeredByOwner} />
31 const navLine = (width: number) => nav && <Button key="turn-nav" plain dimColor label={fitRow(nav.label, width)} onPress={answeredByOwner} />
32 const shared = hook && nav ? sharedWidths(e.props.bodyColumns, cellWidth(nav.label) + 1) : undefined
33
34 if (shared) {
35 return (
36 <Box flexDirection="column">
37 <Box flexDirection="row">
38 {navLine(shared[0])}
39 <Text dimColor> │ </Text>
40 {hookLine(shared[1])}
41 </Box>
42 {below}
43 </Box>
44 )
45 }
46 // A row each, as the two mods draw them on their own.
47 const width = Math.max(12, e.props.bodyColumns - 4)
48 return (
49 <Box flexDirection="column">
50 {navLine(width)}
51 {hookLine(width)}
52 {below}
53 </Box>
54 )
55 })
56}
57hooks/band.ts 41 lines1// East Asian wide and fullwidth ranges plus emoji: a terminal cell pair each.
2const WIDE = /[ᄀ-ᅟ⺀-〾ぁ-㏿㐀-䶿一-鿿ꀀ-가-힣豈-︰-﹏-⦆¢-₩\u{1F300}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u
3
4/** Terminal cells a string takes: wide characters count two. */
5export function cellWidth(text: string): number {
6 let width = 0
7 for (const char of text) width += WIDE.test(char) ? 2 : 1
8 return width
9}
10
11/** Cut with … when needed, then pad the whole tap target to `width` cells. */
12export function fitRow(text: string, width: number): string {
13 let body = text
14 if (cellWidth(body) > width) {
15 let out = ''
16 for (const char of body) {
17 if (cellWidth(out + char) > width - 1) break
18 out += char
19 }
20 body = `${out}…`
21 }
22 return body + ' '.repeat(Math.max(0, width - cellWidth(body)))
23}
24
25// Narrower than this, a line cut to share the row says too little; each keeps a row.
26export const MIN_SHARED = 26
27// The shared row reserves ` │ ` (3 cells) plus the 4 cells each line leaves at the right.
28const SHARED_EXTRA = 7
29
30/**
31 * Each line's width when they share the row, or undefined when they keep a row each.
32 * The navigator line takes what its text needs, at least MIN_SHARED and at most half;
33 * the hook line, whose headline is the longer read, takes the rest.
34 * Returns [navigator width, hook width] in display order.
35 */
36export function sharedWidths(bodyColumns: number, navNeeds: number): [number, number] | undefined {
37 const room = bodyColumns - SHARED_EXTRA
38 const nav = Math.min(Math.max(MIN_SHARED, navNeeds), Math.floor(room / 2))
39 return nav < MIN_SHARED ? undefined : [nav, room - nav]
40}
41