refactor(tui): tighten overlay helpers

- rename overlay help text component to match its role
- share picker window math across model, session, and skills overlays
This commit is contained in:
Brooklyn Nicholson 2026-04-25 14:23:45 -05:00
parent c6fdf48b79
commit 6e83d90eb4
5 changed files with 63 additions and 69 deletions

View file

@ -2,8 +2,6 @@ import { Text, useInput } from '@hermes/ink'
import type { Theme } from '../theme.js'
type TextWrap = 'end' | 'middle' | 'truncate' | 'truncate-end' | 'truncate-middle' | 'wrap' | 'wrap-char' | 'wrap-trim'
export function useOverlayKeys({ disabled = false, onBack, onClose }: OverlayKeysOptions) {
useInput((ch, key) => {
if (disabled) {
@ -20,18 +18,29 @@ export function useOverlayKeys({ disabled = false, onBack, onClose }: OverlayKey
})
}
export function OverlayControls({ children, t, wrap = 'truncate-end' }: OverlayControlsProps) {
export function OverlayHint({ children, t }: OverlayHintProps) {
return (
<Text color={t.color.dim} wrap={wrap}>
<Text color={t.color.dim} wrap="truncate-end">
{children}
</Text>
)
}
interface OverlayControlsProps {
export const windowOffset = (count: number, selected: number, visible: number) =>
Math.max(0, Math.min(selected - Math.floor(visible / 2), count - visible))
export function windowItems<T>(items: T[], selected: number, visible: number) {
const offset = windowOffset(items.length, selected, visible)
return {
items: items.slice(offset, offset + visible),
offset
}
}
interface OverlayHintProps {
children: string
t: Theme
wrap?: TextWrap
}
interface OverlayKeysOptions {