[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

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

chore(prompts): destruct `limitOption` param for better code readability (#457)

Co-authored-by: James Garbutt <43081j@users.noreply.github.com>

authored by

Bartosz Kaszubowski
James Garbutt
and committed by
GitHub
(Feb 24, 2026, 9:43 AM UTC) c3666e2a 667572b2

+21 -14
+5
.changeset/cool-parrots-throw.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + --- 4 + 5 + destruct `limitOption` param for better code readability, tweak types definitions
+16 -14
packages/prompts/src/limit-options.ts
··· 1 - import type { Writable } from 'node:stream'; 2 1 import { getColumns, getRows } from '@clack/core'; 3 2 import { wrapAnsi } from 'fast-wrap-ansi'; 4 3 import color from 'picocolors'; ··· 6 5 7 6 export interface LimitOptionsParams<TOption> extends CommonOptions { 8 7 options: TOption[]; 9 - maxItems: number | undefined; 10 8 cursor: number; 11 9 style: (option: TOption, active: boolean) => string; 10 + maxItems?: number; 12 11 columnPadding?: number; 13 12 rowPadding?: number; 14 13 } ··· 33 32 return { lineCount, removals }; 34 33 }; 35 34 36 - export const limitOptions = <TOption>(params: LimitOptionsParams<TOption>): string[] => { 37 - const { cursor, options, style } = params; 38 - const output: Writable = params.output ?? process.stdout; 35 + export const limitOptions = <TOption>({ 36 + cursor, 37 + options, 38 + style, 39 + output = process.stdout, 40 + maxItems = Number.POSITIVE_INFINITY, 41 + columnPadding = 0, 42 + rowPadding = 4 43 + }: LimitOptionsParams<TOption>): string[] => { 39 44 const columns = getColumns(output); 40 - const columnPadding = params.columnPadding ?? 0; 41 - const rowPadding = params.rowPadding ?? 4; 42 45 const maxWidth = columns - columnPadding; 43 46 const rows = getRows(output); 44 47 const overflowFormat = color.dim('...'); 45 48 46 - const paramMaxItems = params.maxItems ?? Number.POSITIVE_INFINITY; 47 49 const outputMaxItems = Math.max(rows - rowPadding, 0); 48 50 // We clamp to minimum 5 because anything less doesn't make sense UX wise 49 - const maxItems = Math.max(Math.min(paramMaxItems, outputMaxItems), 5); 51 + const computedMaxItems = Math.max(Math.min(maxItems, outputMaxItems), 5); 50 52 let slidingWindowLocation = 0; 51 53 52 - if (cursor >= maxItems - 3) { 53 - slidingWindowLocation = Math.max(Math.min(cursor - maxItems + 3, options.length - maxItems), 0); 54 + if (cursor >= computedMaxItems - 3) { 55 + slidingWindowLocation = Math.max(Math.min(cursor - computedMaxItems + 3, options.length - computedMaxItems), 0); 54 56 } 55 57 56 - let shouldRenderTopEllipsis = maxItems < options.length && slidingWindowLocation > 0; 58 + let shouldRenderTopEllipsis = computedMaxItems < options.length && slidingWindowLocation > 0; 57 59 let shouldRenderBottomEllipsis = 58 - maxItems < options.length && slidingWindowLocation + maxItems < options.length; 60 + computedMaxItems < options.length && slidingWindowLocation + computedMaxItems < options.length; 59 61 60 - const slidingWindowLocationEnd = Math.min(slidingWindowLocation + maxItems, options.length); 62 + const slidingWindowLocationEnd = Math.min(slidingWindowLocation + computedMaxItems, options.length); 61 63 const lineGroups: Array<string[]> = []; 62 64 let lineCount = 0; 63 65 if (shouldRenderTopEllipsis) {