petereon / beaupy

A Python library of interactive CLI elements you have been looking for
https://petereon.github.io/beaupy/
MIT License
181 stars 12 forks source link

Disable spinner when using a debugger #93

Open blairfrandeen opened 1 month ago

blairfrandeen commented 1 month ago

When using a debugging breakpoint when a spinner is running, the text entered in the debugger is continually obscured, while the spinner remains. This means that when debugging, I need to either:

Minimum code to reproduce:

import sys

from beaupy.spinners import DOTS, Spinner

spinner = Spinner(DOTS)
spinner.start()
breakpoint()

This could potentially be fixed by checking for

sys.gettrace() is not None and sys.gettrace().__name__ == "trace_dispatch"

each time the spinner cycles, and stopping the spinner if that's the case.

petereon commented 1 month ago

Thanks for a thorough issue submission and solution suggestion. I am not friendly with pdb, so it will take me some time to set-up and verify the solution. Considering I am presently a little pressed for time, I hope I can deliver a release with a fix towards the end of the week.

blairfrandeen commented 1 month ago

No rush, thank you! I'm also happy to take a crack at it if you prefer.

Looking at the spinner code in this library, I don't actually see anywhere to put the fix, and perhaps instead we should open an issue with rich.Live. It sounds like this was brought up there multiple times but not ever really resolved:

petereon commented 1 month ago

Yep, having refreshed my memory on the spinners code, it seems like a rich dependency issue.

That said, I believe get_renderable callback could be extended with some sort of hack that would stop rendering of the Live display whenever we enter the debugging context, and start again once we leave it.

I'll see about setting up pdb and trying to fix this in rich. If that doesn't pan out, I'll try to hack it on top of beaupy

petereon commented 2 weeks ago

Sorry, got a little bogged down in life-stuff. This issue is not particularly easy to handle considering the layers and layers of abstraction that are required to deal with the terminal in some sort of elegant way that are included in rich.

I've researched the option of hacking it on top of beaupy as well, but I couldn't figure out a somewhat acceptable way to do it.

With that in mind, I will probably not be able to get to this in a foreseeable future 😢 Nonetheless, I'll leave the issue open in case anyone else would like to have a crack at it in a meantime.