Skip to content

Instantly share code, notes, and snippets.

@JanosGit
Created November 23, 2018 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanosGit/168ad4b192b673ce23e0d04d46adb520 to your computer and use it in GitHub Desktop.
Save JanosGit/168ad4b192b673ce23e0d04d46adb520 to your computer and use it in GitHub Desktop.
#pragma once
#include <juce_events/juce_events.h>
namespace ntlab
{
/**
* A simple helper class that polls stdin for available characters and calls a callback function if there
* is a new line available from stdin. Make sure to only implement one instance of this in your application.
*/
class AsyncStdinListener : private juce::Timer
{
public:
/** Creates an instance of AsyncStdinListener that instantly keeps listening to stdin */
AsyncStdinListener();
/** Async callback that gets called from the message thread if the user inputted a line on stdin */
virtual void handleStdin (juce::String& userInput) = 0;
private:
bool stdinCharactersAvailable();
void timerCallback() override;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment