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

New spinner with option #148

Merged
merged 7 commits into from
Jul 1, 2022

Conversation

inkel
Copy link
Contributor

@inkel inkel commented May 3, 2022

This PR introduces a spinner.Option type that allows passing configuration options when creating new spinners using spinner.New. This doesn't break existing code as it uses variadic arguments, so any existing code as the following should continue to work:

s := spinner.New()
s.spinner = spinner.Dot

This code now can be written as:

s := spinner.New(spinner.WithSpinner(spinner.Dot))

In order not to be overly verbose, a With function was defined for each of the pre-existing spinners, so one can have for instance:

s := spinner.New(spinner.withPulse())

Last but not least it also adds a WithStyle(lipgloss.Style) option function.

This is mostly syntactic sugar, but helps when you have a custom model and want to create it:

func New() MyModel {
    return MyModel{
        spinner: spinner.New(spinner.WithDot(), spinner.WithStyle(myStyle)),
    }
}

Without these functions the call above has to be written as:

func New() MyModel {
    m := MyModel{
        spinner: spinner.New(),
    }
    m.spinner.Spinner = spinner.Dot
    m.spinner.Style = myStyle

    return m
}

inkel added 6 commits May 3, 2022 15:27
Signed-off-by: Leandro López (inkel) <[email protected]>
This doesn't break existing code as it uses variadic arguments, so
any existing code as the following should continue to work:

    s := spinner.New()
    s.spinner = spinner.Dot

This change allows for instead of those two lines, having a call:

   s := spinner.New(spinner.WithSpinner(spinner.Dot))

Signed-off-by: Leandro López (inkel) <[email protected]>
Signed-off-by: Leandro López (inkel) <[email protected]>
Signed-off-by: Leandro López (inkel) <[email protected]>
@inkel
Copy link
Contributor Author

inkel commented May 19, 2022

Any updates on this? It'd be nice to at least have the CI checks feedback 😬

@muesli
Copy link
Contributor

muesli commented May 19, 2022

We'll review this as soon as possible, just a bit more patience, please 🙂

@maaslalani
Copy link
Contributor

Hey @inkel, this looks great. Thank you for adding docs/comments and tests!
I removed the aliases for the specific spinners since I personally didn't feel they were necessary as they increase the API surface area and we can always add them later if people request them but they would be difficult to take them out.

@maaslalani maaslalani merged commit 7cc5786 into charmbracelet:master Jul 1, 2022
@inkel inkel deleted the new-spinner-with-option branch July 1, 2022 19:00
@inkel
Copy link
Contributor Author

inkel commented Jul 1, 2022

Thank you @maaslalani !!! Your decision of removing the specific spinners makes total sense, good call!

maaslalani added a commit that referenced this pull request Jul 5, 2022
…e` options (#148)

* Add spinner.New test

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.Option type and spinner.WithSpinner option

Signed-off-by: Leandro López (inkel) <[email protected]>

* Allow passing options in spinner.New

This doesn't break existing code as it uses variadic arguments, so
any existing code as the following should continue to work:

    s := spinner.New()
    s.spinner = spinner.Dot

This change allows for instead of those two lines, having a call:

   s := spinner.New(spinner.WithSpinner(spinner.Dot))

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.WithX option for each spinner.Spinner

Signed-off-by: Leandro López (inkel) <[email protected]>

* Refactor spinner tests

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.WithStyle option function

Signed-off-by: Leandro López (inkel) <[email protected]>

* refactor: remove With... Spinner aliases

Co-authored-by: Maas Lalani <[email protected]>
ReallyLiri pushed a commit to ReallyLiri/bubbles that referenced this pull request Jun 13, 2024
…e` options (charmbracelet#148)

* Add spinner.New test

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.Option type and spinner.WithSpinner option

Signed-off-by: Leandro López (inkel) <[email protected]>

* Allow passing options in spinner.New

This doesn't break existing code as it uses variadic arguments, so
any existing code as the following should continue to work:

    s := spinner.New()
    s.spinner = spinner.Dot

This change allows for instead of those two lines, having a call:

   s := spinner.New(spinner.WithSpinner(spinner.Dot))

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.WithX option for each spinner.Spinner

Signed-off-by: Leandro López (inkel) <[email protected]>

* Refactor spinner tests

Signed-off-by: Leandro López (inkel) <[email protected]>

* Add spinner.WithStyle option function

Signed-off-by: Leandro López (inkel) <[email protected]>

* refactor: remove With... Spinner aliases

Co-authored-by: Maas Lalani <[email protected]>
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.

3 participants