Closed joetannenbaum closed 1 year ago
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.
Understood. Ok I'll tinker with this and see if I can get it working correctly under those parameters, thanks for explaining!
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.
Awesome! Thanks for the tip on the debug branch, super useful. I'll keep you posted 👍
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:
You would get the resulting output:
Before:
After: