[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.

feat(@clack/prompts): dynamic max items (#174)

authored by

Christian Preston and committed by
GitHub
(Mar 20, 2024, 10:29 AM EDT) e74d4486 0cb17d3b

+9 -2
+5
.changeset/light-laws-judge.md
··· 1 + --- 2 + '@clack/prompts': patch 3 + --- 4 + 5 + feat: adaptative max items
+4 -2
packages/prompts/src/index.ts
··· 8 8 SelectKeyPrompt, 9 9 SelectPrompt, 10 10 State, 11 - TextPrompt 11 + TextPrompt, 12 12 } from '@clack/core'; 13 13 import isUnicodeSupported from 'is-unicode-supported'; 14 14 import color from 'picocolors'; ··· 68 68 const limitOptions = <TOption>(params: LimitOptionsParams<TOption>): string[] => { 69 69 const { cursor, options, style } = params; 70 70 71 + const paramMaxItems = params.maxItems ?? Infinity; 72 + const outputMaxItems = Math.max(process.stdout.rows - 4, 0); 71 73 // We clamp to minimum 5 because anything less doesn't make sense UX wise 72 - const maxItems = params.maxItems === undefined ? Infinity : Math.max(params.maxItems, 5); 74 + const maxItems = Math.min(outputMaxItems, Math.max(paramMaxItems, 5)); 73 75 let slidingWindowLocation = 0; 74 76 75 77 if (cursor >= slidingWindowLocation + maxItems - 3) {