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

Displaying a final message when rendering spinner #97

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joetannenbaum
Copy link
Contributor

This PR introduces an optional third argument to the spin helper, allowing the user to display a final message after the spinner has completed its process.

The message can either be a string:

spin(
    function () {
        sleep(4);

        return 'A-OK';
    },
    'Checking system...',
    'System looks good!',
);

or a closure that receives the result as an argument:

spin(
    function () {
        sleep(4);

        return '8.2';
    },
    'Detecting PHP Version...',
    fn ($result) => "PHP Version: <info>{$result}</info>",
);

Here's what it looks like:

CleanShot.2023-10-21.at.15.11.52.mp4

@joetannenbaum
Copy link
Contributor Author

I realized yesterday after submitting this PR that since the spinner erases itself, you could just output a message yourself using something like info afterwards.

I still like the idea of the spinner taking care of this for you, but if you're not into the idea of adding an additional argument let me know.

@asciito
Copy link

asciito commented Oct 23, 2023

I realized yesterday after submitting this PR that since the spinner erases itself, you could just output a message yourself using something like info afterwards.

I still like the idea of the spinner taking care of this for you, but if you're not into the idea of adding an additional argument let me know.

Personally I prefer the addition of this feature, just because more than once I have to print a message just right before the spinner ends. So for example, if need to perform a lot of tasks and then print a message for every task, well, I really prefer this approach instead of writing more info functions every time.

@taylorotwell taylorotwell marked this pull request as draft October 24, 2023 13:47
@mho22
Copy link

mho22 commented Mar 30, 2024

@joetannenbaum I created a quick artisan command to test the solution you proposed in case this pull request isn't merged, and it seems to have a minor newline issue :

app\Console\Commands\Test.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use function Laravel\Prompts\spin;
use function Laravel\Prompts\info;


class Test extends Command
{
    protected $signature = "test";

    public function handle() : void
    {
        spin( fn() => sleep( 2 ), "Sleeping..." );

        info( "Awake" );

        spin( fn() => sleep( 2 ), "Sleeping..." );

        info( "Awake" );

        spin( fn() => sleep( 2 ), "Sleeping..." );

        info( "Awake" );
    }
}
Enregistrement.de.l.ecran.2024-03-30.a.20.39.01.mov

It appears that when a spin is called for the second time and an info is added afterward, there is a new line between them.

@jessarcher I suppose I should maybe add this as an issue ?

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