Skip to content

Instantly share code, notes, and snippets.

@JanosGit
Created November 23, 2018 14:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JanosGit/8c4e794679391a2cddc13c1f12af7a56 to your computer and use it in GitHub Desktop.
#include "AsyncSdtinListener.h"
namespace ntlab
{
AsyncStdinListener::AsyncStdinListener ()
{
startTimer (100);
}
void AsyncStdinListener::timerCallback ()
{
if (stdinCharactersAvailable ())
{
std::string commandLineInput;
std::getline (std::cin, commandLineInput);
juce::String commandLineInputJuceString (commandLineInput);
handleStdin (commandLineInputJuceString);
}
}
}
#ifdef JUCE_WINDOWS
#include <conio.h>
namespace ntlab
{
bool AsyncStdinListener::stdinCharactersAvailable()
{
return _kbhit() > 0;
}
}
#else
#include <poll.h>
namespace ntlab
{
bool AsyncStdinListener::stdinCharactersAvailable()
{
static struct pollfd pollFileDescriptor {fileno (stdin), POLLIN, 0};
return poll (&pollFileDescriptor, 1, 0) > 0;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment