fadeevab / cliclack

Beautiful, minimal, opinionated CLI prompts inspired by the Clack NPM package
MIT License
205 stars 13 forks source link

[bug] issues when rendering a select whose items are longer than the active terminal viewport #64

Open cylewitruk opened 1 month ago

cylewitruk commented 1 month ago

Just ran into this for the first time -- seems that if the select is long, your cursor will be placed at the bottom while the first selected item is at the top, outside of the active terminal. If you scroll up to see the active item and then press "down" to the next item, it will indeed select the correct item, but the entire list will be re-rendered and the cursor placed again at the bottom. Once the active item comes into the viewport, then it navigates correctly; the issue seems to be when the active item is outside of the viewport.

Hard to explain, easiest reproduced by creating a select with enough items to overflow the active terminal viewport and pressing buttons :sweat_smile:

Here's a gif: cliclack_long_select

One thing that would be nice here is to be able to specify a maximum size for the select, i.e. max height 5 lines and then scrolling the items when navigating up/down. In my example above, I don't really want my user's terminal to be spammed with all possible bitcoin core versions, it's most likely one of the most recent versions they're interested in, but I don't want to deny them older versions either. So only displaying i.e. the 5 most recent versions at first would be a benefit.

Not quite sure how to implement this if I were to take a stab at it...

fadeevab commented 1 month ago

@cylewitruk What a nasty bug :) Most likely, this one is gonna be tricky to fix, but let's see.

cylewitruk commented 1 month ago

@fadeevab For now I've just limited the select to the 5 most recent versions as I think that's the 98% use-case, so no rush, but yeah this is something that should be looked into anyway :) If I get some free time I'll play around with it.