Closed Tina-otoge closed 1 year ago
Thanks for your bug report. Yes, simple-term-menu should not alter the terminal environment on unsupported platforms or at least should restore the initial state on errors automatically. I am curious: On which system happens the libc load error?
On which system happens the libc load error?
On Termux (Android)
Quite the edge case but it was an important environment target for my project.
I added a patch for the libc
and wcwidths
loading issues to the latest develop
branch. The wcwidths
function now has a default fall back to the Python len
function which is not perfect but is better than nothing and does not crash the menu any more.
I could not reproduce the problems with tput
. In my tests, an exception is raised, but the terminal state is left untouched.
Other errors which could occur during the show
method should not lead to terminal state issues since there is a call to _reset_term
in a finally
block.
Could you please test the latest patch? You can obtain the latest development version directly from the GitHub repository:
pip install git+https://github.com/IngoMeyer441/simple-term-menu@develop
It indeed does not fail anymore now 🙏
https://user-images.githubusercontent.com/9400466/191036584-fe887041-493d-4973-ae9f-9d9523af9a20.mp4
Great, I can create a bug fix release later 👍
Sorry for the delay, the bug fix release is finally released on PyPI. Feel free to reopen if necessary.
First off, thank you for this library.
I'm writing a script that can be run on many different platforms. I first attempt to run
TerminalMenu.show
, if it fails, I revert to a simpler prompt usingprint
andinput
.The way I'm achieving this is by doing something like so
However, before throwing an exception, TerminalMenu, runs some modifications on the terminal that leaves it in an unusable state, we can not grab any input from the user anymore. The call to
input
stay hanging forever with no way to input any text.Currently, my approach is to run
TerminalMenu._reset_term()
before the call toinput
, which fixes my issue, but 1) feels ugly because I'm calling a private and 2) would be best if the terminal was left untouched if TerminalMenu isn't going to workIt would be great if TerminalMenu could determine ahead of time that it is not going to be able to work, and do not modify the terminal at all by aborting early if so.
Example traceback on an unsupported environment:
Here the issue is libc.so.6 not being available, a similar error occurs if
tput
is not available.Usage in an actual project: https://github.com/Tina-otoge/nyaadl/blob/45dc11d09bd0a8d71b7ec0f34ce511c8b3c2039a/src/nyaadl/cli.py#L51-L54