Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: replace AlecAivazis/survey with charmbracelet/bubbletea#14475

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DanielleMaywood merged 28 commits intomainfromdm-replace-survey-with-bubbletea
Sep 4, 2024

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywoodDanielleMaywood commentedAug 29, 2024
edited
Loading

fixes#12720

This PR replaces the unmaintainedhttps://github.com/AlecAivazis/survey library withhttps://github.com/charmbracelet/bubbletea.

The existing tests for the componentsSelect,RichSelect andMultiSelect do not test anything meaningful as the components short-circuit to return the first option when ran in a test and the tests just confirm this short-circuiting behaviour. Future work will be to remove this short-circuiting behaviour and fix the tests.

I've manually tested the behaviour of the components with:

@DanielleMaywoodDanielleMaywoodforce-pushed thedm-replace-survey-with-bubbletea branch 3 times, most recently from88d286f to2b063b0CompareSeptember 3, 2024 09:25
@DanielleMaywoodDanielleMaywood marked this pull request as ready for reviewSeptember 3, 2024 09:25
func (m multiSelectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd

if msg, ok := msg.(tea.KeyMsg); ok {
Copy link
Member

Choose a reason for hiding this comment

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

nit: invert and early return

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've slightly changed the logic here. I just noticed it is slightly different to how thefunc (m selectModel) Update function works.m.search.Update can handle more than just atea.KeyMsg. With the updated logic does this still make sense?

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Nice work, and thanks for the asciinemas! Left a few comments on changes I'd like to see in all functions/models, but otherwise looks good.

}

func (selectModel) Init() tea.Cmd {
return textinput.Blink
Copy link
Member

Choose a reason for hiding this comment

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

I found the blinking fairly distracting in the aciinemas, that behavior seemed different from the original. Is this what controls it and should we actually blink?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, this is what controls ithttps://pkg.go.dev/github.com/charmbracelet/bubbles@v0.19.0/textinput#Blink.

I'm happy to back it out

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Doing some more research, it appears that thetextinput component also triggers the blinking behaviour

mafredri reacted with confused emoji
func (m selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd

if msg, ok := msg.(tea.KeyMsg); ok {
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the program receives akill -INT $PID while tea is active? Do we handle it nicely?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Unless I'm doing something wrong, it appears nothing happens?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, did you try with acoder command or cliui test binary? Withcoder I would expect the program to exit with a cancelled.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I used thecliui binary withgo run ./cmd/cliui select. I shall try against the coder binary

Copy link
Member

Choose a reason for hiding this comment

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

I checked onmain and this behaviour appears to be the status quo.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Just tested and it does not! Need to handle that then,err isnil

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

@DanielleMaywoodDanielleMaywoodSep 3, 2024
edited
Loading

Choose a reason for hiding this comment

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

I can confirm by disabling the builtin signal handler it is possible to geterr to contain theCanceled error.

I wrote a small signal handler

typeterminateMsgstruct{}funcinstallSignalHandler(p*tea.Program)chanstruct{} {ch:=make(chanstruct{})gofunc() {sig:=make(chan os.Signal,1)signal.Notify(sig,syscall.SIGINT,syscall.SIGTERM)deferfunc() {signal.Stop(sig)close(ch)}()for {select {case<-ch:returncase<-sig:p.Send(terminateMsg{})}}}()returnch}

Then install it on a*tea.Program

ch:=installSignalHandler(p)deferfunc() {ch<-struct{}{}}()

And handle it in theUpdate methods

switchmsg:=msg.(type) {caseterminateMsg:m.canceled=truereturnm,tea.Quit

If this seems okay I can push this change?@mafredri

Copy link
Member

Choose a reason for hiding this comment

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

Might I suggest returning a func instead of the channel for close/deregistering the handler? I feel the usage will be a bit more idiomatic/easy to understand.

On the other hand, perhaps we don't need to handle signals at all and leave it to be the responsibility of thecoder command that needs it? I guess it's possible the terminal is left in a bad state unless the signal is handled though (not sure if it enters raw mode or not).

PS. You might want to only handlesignal.Interrupt for the Windows compatibility.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, definitely a good idea. Have made that change 👍

Killing the process withkill -TERM $PID leaves the cursor in a bad state if we don't explicitly handle it (syscall.SIGTERM).

Will push these changes up, can always revert if unhappy.

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Nice work and thorough testing!

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

LGTM after the conflicts are resolved, nice work!

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Feel free to merge once you updateflake.nixgo.mod and make CI happy. Nice contribution!

@DanielleMaywoodDanielleMaywoodforce-pushed thedm-replace-survey-with-bubbletea branch 3 times, most recently from7f32e05 to6d87a98CompareSeptember 4, 2024 09:30
@DanielleMaywoodDanielleMaywoodforce-pushed thedm-replace-survey-with-bubbletea branch from6d87a98 to966f772CompareSeptember 4, 2024 10:19
@DanielleMaywoodDanielleMaywood merged commit1958436 intomainSep 4, 2024
28 checks passed
@DanielleMaywoodDanielleMaywood deleted the dm-replace-survey-with-bubbletea branchSeptember 4, 2024 10:38
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsSep 4, 2024
@Emyrk
Copy link
Member

Late to the party, but one thing that bothered me with thesurvey package was that the prompt question remained after it was answered. I wonder if we can fix that now.

@DanielleMaywood
Copy link
ContributorAuthor

Late to the party, but one thing that bothered me with thesurvey package was that the prompt question remained after it was answered. I wonder if we can fix that now.

This absolutely can be changed now! Personally I prefer the question (with the answer) remaining, so I'd be curious if there is any way of finding out if that would be a positive/negative change amongst our customers.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@DanielleMaywoodDanielleMaywood

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AlecAivazis/survey is no longer maintained
5 participants
@DanielleMaywood@Emyrk@mafredri@johnstcn@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp