Skip to content

Commit e74d448

Browse files
authored
feat(@clack/prompts): dynamic max items (#174)
2 parents 0cb17d3 + f33a56f commit e74d448

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/light-laws-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clack/prompts': patch
3+
---
4+
5+
feat: adaptative max items

packages/prompts/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SelectKeyPrompt,
99
SelectPrompt,
1010
State,
11-
TextPrompt
11+
TextPrompt,
1212
} from '@clack/core';
1313
import isUnicodeSupported from 'is-unicode-supported';
1414
import color from 'picocolors';
@@ -68,8 +68,10 @@ interface LimitOptionsParams<TOption> {
6868
const limitOptions = <TOption>(params: LimitOptionsParams<TOption>): string[] => {
6969
const { cursor, options, style } = params;
7070

71+
const paramMaxItems = params.maxItems ?? Infinity;
72+
const outputMaxItems = Math.max(process.stdout.rows - 4, 0);
7173
// 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));
7375
let slidingWindowLocation = 0;
7476

7577
if (cursor >= slidingWindowLocation + maxItems - 3) {

0 commit comments

Comments
 (0)