Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pass on cursor tracking select focus #358

Merged
merged 4 commits into from Aug 23, 2021
Merged

first pass on cursor tracking select focus #358

merged 4 commits into from Aug 23, 2021

Conversation

vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Jun 16, 2021

Fixes #305

This solution is inelegant and brittle but it does work 馃槄 please let me know if I should add more test coverage.

@AlecAivazis
Copy link
Owner

AlecAivazis commented Jun 17, 2021

Hey @vilmibm - thanks for submitting this! I'll try to find some time this weekend to pull it down and give it a shot.

It's been awhile since I've looked at the code for paginate but I think you should be able to use the second returned value to figure out how many lines to move up (assuming that the cursor is always starting at the bottom of a list pageSize long). If that doesn't work for some reason, then you would need to have some other way of identifying the correct line and your approach would make sense. Here are the tests for paginate so you can get a feeling for how it behaves.

EDIT: it might make sense to bake this directly into paginate so we get accessibility "for free" in the multi-line inputs 馃

@vilmibm
Copy link
Contributor Author

vilmibm commented Jun 17, 2021

Using the paginate output is a great idea; I don't know why my eyes just glossed right past the output of paginate.

I'll add support for wide option lines and get this cleaned up.

EDIT: regarding adding to paginate; I believe that would require it having access to a Renderer, right? paginate is nicely independent of the prompts that make use of it right now.

@AlecAivazis
Copy link
Owner

Ah yea, good point. Maybe a reasonable solution is to add a method to Renderer that invokes and returns the values from paginate along with moving the cursor? That will keep the actual page logic pure and easily testable but still give us the behavior without having to implement it in multiple places. Thoughts?

@vilmibm
Copy link
Contributor Author

vilmibm commented Jun 18, 2021

Let me know what you think of the current approach; it's not the most elegant (the width() method for the prompts is a brittle thing) but I think it keeps things testable / comprehensible.

Unfortunately I broke multi-select rendering so I'll fix that tomorrow; if you are ok with this approach though in general I'll go ahead and add tests as needed.

multiselect.go Outdated Show resolved Hide resolved
@vilmibm vilmibm marked this pull request as ready for review July 2, 2021 21:13
@vilmibm
Copy link
Contributor Author

vilmibm commented Jul 2, 2021

I was waylaid by work stuff but finally marking this as non-draft. This solution is not the best but it does work; it will be a little annoying to support it in new prompt types, but it will weather icons of variable length when computing the width/word wrapping of long options.

@vilmibm vilmibm requested a review from AlecAivazis July 2, 2021 21:15
@AlecAivazis
Copy link
Owner

Sorry i haven't gotten to this yet @vilmibm. work was really busy this week, will try to find some time to look at it over the weekend

Copy link
Owner

@AlecAivazis AlecAivazis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this took me so long to look at! I'm buying a home and have been very busy running back and forth to wrangle all of the moving parts. Thanks for being patient

multiselect.go Outdated Show resolved Hide resolved
select.go Outdated Show resolved Hide resolved
@vilmibm
Copy link
Contributor Author

vilmibm commented Jul 22, 2021

@AlecAivazis buying a house seems so stressful -- no rush on my part and good luck!

I followed up on those two comments, but I think I have some test fixing to do 馃槄 I guess because I'm injecting more control sequences the virtual terminal tests need to be reconciled? I'll start work on that; let me know if you have any protips.

EDIT: actually it looks like the failing tests from a previous commit of my may have been flakes? They pass fine locally on Ubuntu and looking at them in Actions it feels like an actions problem (availability blip or something). I guess we'll find out once the tests are approved to run again.

@AlecAivazis
Copy link
Owner

Oh damn sorry I didn't realize they were still pending. GitHub didn't notify me about your edit so I totally missed that. I just kicked them off

Copy link
Owner

@AlecAivazis AlecAivazis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally found some time to pull this down and test it. The select and multi select tests all ran smoothly (located at tests/{select.go, multiselect.go} but if I ran another test afterwards, the prompt would print many lines above the starting line. I think there is a problem in the way the select and multiselect prompts clean up

@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 3, 2021

hm, can you help me with some more context?

I'm running this locally:

go test -v github.com/AlecAivazis/survey/v2 github.com/AlecAivazis/survey/v2/core github.com/AlecAivazis/survey/v2/terminal -mod=vendor which is failing for me locally against both master and my PR for reasons seemingly unrelated to my changes. It seems like they are passing in CI, though?

How are you triggering the failure?

@AlecAivazis
Copy link
Owner

AlecAivazis commented Aug 3, 2021

Ah yea sure. So there is this directory which contains scripts, not actual tests, that are meant to be run manually in order to verify that things behave in a real scenario. If you run the select and multi select tests everything behaves correctly but if I run the confirm test (just typing go run tests/confirm.go from the root of the repo) i see the issue

@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 9, 2021

@AlecAivazis ah oops, I screwed up the tiny refactor and was restoring the cursor when I shouldn't have been by accident. Fixed now; running through the stuff in tests/ seems to work fine.

@AlecAivazis
Copy link
Owner

Awesome! Thanks for hunting that down! I finally found the time to pull down your branch and test it out. Sorry that took so long - was on vacation for 10 days.

I'm pretty sure this is good to go but I want to give it one more go around. Pretty excited we should be getting this in soon

Copy link
Owner

@AlecAivazis AlecAivazis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to finally merge this in. Thanks so much for implementing this @vilmibm!

@AlecAivazis AlecAivazis merged commit a4e159a into AlecAivazis:master Aug 23, 2021
@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 23, 2021

awesome news! thank you!!

@billygriffin
Copy link

Great news @AlecAivazis, thanks for working with us to get it across the finish line. And great work @vilmibm! 馃帀 鉂わ笍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Put cursor on selected line
3 participants