chuck
chuck copied to clipboard
KBHit leaves terminal in broken state
Example file:
KBHit kb;
After chuck
exits, anything typed in the terminal isn't displayed.
Tested on macOS 10.15.4.
confirmed on MacOS High Sierra 10.13.1
that said, commands can be entered after the script ends, just letters aren't visible. tried running somethings like
ls -a
and I can see the outcome
I am also seeing this on Sierra 10.12.6, with the kb2.ck example. @spencersalazar any ideas?
this also happens on Ubuntu Studio 20.04 LTS
Hmm probably this function not being run: https://github.com/ccrma/chuck/blob/0f5da2cf28892e1dcc5bf7eb02bf44d7c882f654/src/core/util_console.cpp#L158-L172
chuck sets up the console to disable key echo when you use KBHit -- it then restores the previous settings on exit using this function. But it looks like this function isn't called- @lathertonj maybe this is from the big refactor of a few years ago? Do you know the best place to put this function to have it called on shutdown? It looks like its meant to be called via KBHitManager::shutdown
.
I think this could be called in global_cleanup()
in chuck_main.cpp. But that wouldn't fix the issue for embedded versions of ChucK -- is that a problem? We could also put something in the ~Chuck() destructor, but then I'm not sure what would happen if there are multiple VMs going and one of them decides to run this cleanup function while another is relying on the behavior...
I dont think embedded ChucK would be a problem -- KBHit only works on Unix-y terminal environments or at least has been mainly aimed at that; Im not sure if its expected to work in any current known embedding environments. So this seems like a promising fix.