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

Remove extra line spin leaves behind #72

Closed

Conversation

joetannenbaum
Copy link
Contributor

I found that when using spin, it leaves an extra line behind, creating a gap in output. Not sure if it's intentional, but in this PR I moved the cursor up one line before returning the result of the callback.

Given the following code:

text('First question');
text('Second question');

$result = spin(
    function () {
        sleep(4);

        return 'Callback return';
    },
    'Installing dependencies...',
);

info($result);
info('Also this!');

You would get the resulting output:

Before:

CleanShot 2023-09-17 at 14 15 30@2x

After:

CleanShot 2023-09-17 at 14 15 09@2x

@jessarcher
Copy link
Member

Hey @joetannenbaum, thanks for the PR!

This one is a little complicated. I can confirm the issue you've demonstrated, but there are some different issues with this solution. For example, if you put a spinner as the first output, or put two spinners in a row, then it erases too much.

It all has to do with how each prompt determines how many newlines to output above the prompt, which involves looking at the trailing newlines previously output on the buffer (and also handling the case where nothing was previously output).

Ultimately it would be great if the spinner could restore the console output to how it was and also restore the previous trailing newline count so the next prompt calculates things as though the spinner was never there, rather than considering whatever trailing newlines the spinner output before being erased.

@jessarcher jessarcher marked this pull request as draft September 18, 2023 04:45
@jessarcher jessarcher added the bug label Sep 18, 2023
@joetannenbaum
Copy link
Contributor Author

Understood. Ok I'll tinker with this and see if I can get it working correctly under those parameters, thanks for explaining!

@jessarcher
Copy link
Member

Feel free to let me know if you have trouble, and I'll see if I can help.

I have a branch at https://github.com/laravel/prompts/compare/debug-markers?expand=1 that allows you to visually see newline characters and render cycle counts. It tries not to get in the way of the output, but I think results in an extra line after the command finishes because of the trailing render count on the final line. Debugging with Ray is sometimes easier to see what's happening without impacting the console output.

@joetannenbaum
Copy link
Contributor Author

Awesome! Thanks for the tip on the debug branch, super useful. I'll keep you posted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants