daniele77 / cli

A library for interactive command line interfaces in modern C++
Boost Software License 1.0
1.23k stars 140 forks source link

how to trap keypress inside a command? #221

Closed elbrandt closed 9 months ago

elbrandt commented 10 months ago

Hi, Fantastic library, well written and feature packed. Thanks for your work. We're using CliLocalTerminalSession with a LoopScheduler. One of the commands we've implemented, we'd like the command to run in a loop 'until the user presses a key' to end the command and return to the menu.

When we implement this in our command's lambda using the select() function, they way we typically would in a regular command line app, I find that we're in a race condition with a thread running the same select() command in an instance of the LinuxKeyboard class. So, I think either we're doing it wrong, or this "run command until key is pressed" use case isn't supported in this library. Is there a relatively pain-free way to do what we want? Can we somehow temporarily pause the scheduler within our command? I can elaborate more on the use case if this question is unclear. Thanks again for an excellent library. -Eric.