chuck icon indicating copy to clipboard operation
chuck copied to clipboard

KBHit leaves terminal in broken state

Open mohd-akram opened this issue 4 years ago • 7 comments

Example file:

KBHit kb;

After chuck exits, anything typed in the terminal isn't displayed.

Tested on macOS 10.15.4.

mohd-akram avatar Apr 16 '20 16:04 mohd-akram

confirmed on MacOS High Sierra 10.13.1

mariobuoninfante avatar Apr 20 '20 11:04 mariobuoninfante

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

mariobuoninfante avatar Apr 20 '20 11:04 mariobuoninfante

I am also seeing this on Sierra 10.12.6, with the kb2.ck example. @spencersalazar any ideas?

lathertonj avatar Apr 20 '20 16:04 lathertonj

this also happens on Ubuntu Studio 20.04 LTS

mariobuoninfante avatar Aug 18 '20 22:08 mariobuoninfante

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.

spencersalazar avatar Aug 23 '20 20:08 spencersalazar

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...

lathertonj avatar Aug 24 '20 17:08 lathertonj

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.

spencersalazar avatar Aug 28 '20 00:08 spencersalazar