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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the spinner drops out prematurely, input is invisible #236

Open
flippedcracker opened this issue May 14, 2024 · 5 comments
Open

If the spinner drops out prematurely, input is invisible #236

flippedcracker opened this issue May 14, 2024 · 5 comments
Labels
bug Something isn't working input spinner

Comments

@flippedcracker
Copy link

Describe the bug
If I start a spinner and something exits out (like a os.Exit() or log.Fatal() ), then the input in the terminal is hidden. The only way to get it back is to reset terminal

To Reproduce
Steps to reproduce the behavior:

  1. Start a spinner
  2. exit out of the spinner Action function by way of os.Exit or log.Fatal
  3. try to type in the terminal
  4. see the nothing shows in the terminal

Expected behavior
Exiting out should return to terminal as normal

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Ubuntu 22

Additional context
Add any other context about the problem here.
2024-05-14_13-55

@maaslalani
Copy link
Contributor

Hey, can you confirm that this is a different issue than #159?

If so, we can combine the issues for some clean up. Otherwise, thank you so much for the issue!

@caarlos0 caarlos0 added bug Something isn't working input spinner labels Nov 26, 2024
@caarlos0
Copy link
Member

can you share a reproducible?

@flippedcracker
Copy link
Author

Here is a basic reproducible

`package main

import (
	"fmt"
	"log"
	"os"
	"time"

	"github.com/charmbracelet/huh/spinner"
)

func main() {
	err := spinner.New().
		Title("Doing something in the background").
		Action(func() {
			time.Sleep(5 * time.Second)
			fmt.Println("The something failed")
			os.Exit(1)
		}).Run()
	if err != nil {
		log.Fatal(err)
	}
}`

@caarlos0
Copy link
Member

ah, yes, the problem is the Exit(1)

Exit skips all defers and what not, so there's not anything we can do here I think https://pkg.go.dev/os#Exit

We need better ways to handle this, I think #292 is a good start, as you can make an action that returns an error for example.

@caarlos0
Copy link
Member

fwiw with #292 you can do something like:

package main

import (
	"context"
	"errors"
	"log"
	"time"

	"github.com/charmbracelet/huh/spinner"
)

func main() {
	err := spinner.New().
		Title("Doing something in the background").
		ActionErr(func(context.Context) error {
			time.Sleep(1 * time.Second)
			return errors.New("something went wrong")
		}).Run()
	if err != nil {
		log.Println(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input spinner
Projects
None yet
Development

No branches or pull requests

3 participants