peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.61k stars 238 forks source link

Leave and re-enter asciimatics mode? #366

Closed ymyke closed 1 year ago

ymyke commented 1 year ago

Hi @peterbrittain –

Is there a way to leave and re-enter asciimatics mode? I.e., to close and reopen the Screen?

Use case: To open a pdb session at some point in my program and inspect the state, ideally with the ability to continue the program afterwards.

peterbrittain commented 1 year ago

It is possible using the Screen.open() and Screen.close() methods, but as you can see in the docs, that means you have a new screen object after the open call and so need to plumb that through to the rest of your code.

I guess you could make use of the existing logic to resize and throw a new exception that you catch in the main loop, close the screen and invoke the debugger, but you will lose some program state. I typically use logging rather than pdb for this reason.

ymyke commented 1 year ago

That works great, thank you! (In my case, the view containing the Screen is stored in a global variable anyway so it's no issue to update it.)