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

Allow re-rendering during progress callback #155

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

jessarcher
Copy link
Member

@jessarcher jessarcher commented Jun 17, 2024

This PR allows developers to update the progress label and hint at any point during their callback by calling the render method on the Progress class. Previously, a re-render only occurred between each step, so updating the label or hint to reflect what was about to happen was not possible.

progress(
    label: 'Uploading...',
    steps: [
        'file1.zip',
        'file2.zip',
        'file3.zip',
    ],
    callback: function ($step, $progress) {
        $progress
            ->label("Uploading {$step}...")
            ->hint(rand(5, 10).'MB')
            ->render();

        sleep(5);

        // It doesn't make sense to call `render` here because the prompt will already
        // re-render to update the progress bar once this callback is completed.
        $progress->label("Uploaded {$step}");
    },
);

Additional render calls on each iteration can add up to a meaningful delay over a lot of iterations, so I don't think it makes sense to always force a re-render on every call to the label or hint methods.

Fixes #153

@jessarcher jessarcher marked this pull request as ready for review June 17, 2024 00:23
@taylorotwell taylorotwell merged commit 409b0b4 into main Jun 17, 2024
5 checks passed
@taylorotwell taylorotwell deleted the allow-rerendering-during-progress-steps branch June 17, 2024 13:58
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.

Progress bar label and hint not updating immediately
2 participants