23 if (_running || _thread.joinable()) {
36 std::cout <<
"Thread started" << std::endl;
75 PRETTY_INFO <<
"Injecting the 'q' key to stop the thread." << std::endl;
76 _userControls.setLooping(
false);
77 _userControls.setPlaying(
false);
78 std::cin.putback(
'q');
79 std::cin.putback(
'\n');
80 std::cin.putback(
'\n');
81 std::cin.putback(
'\n');
82 std::cin.putback(
'\n');
83 if (_thread.joinable()) {
112 _userControls.setEcho(echo);
122 _userControls.setHelp(help);
132 _userControls.setPlaying(playing);
142 _userControls.setLooping(looping);
152 _userControls.setRecording(recording);
162 _userControls.setUserChoice(userChoice);
172 return _userControls.isEcho();
182 return _userControls.isHelp();
192 return _userControls.isPlaying();
202 return _userControls.isLooping();
212 return _userControls.isRecording();
222 return _userControls.hangUpTheCall();
230 _userControls.showPrompt();
238 _userControls.toggleEcho();
246 _userControls.toggleHelp();
254 _userControls.togglePlaying();
262 _userControls.toggleLooping();
270 _userControls.toggleRecording();
281 std::string indentation =
"";
282 for (
unsigned int i = 0; i < indent; ++i) {
285 std::string result = indentation +
"Thread Capsule:\n";
287 result += indentation +
"- User Controls: {\n" + _userControls.getInfo(indent + 1) + indentation +
"}\n";
#define PRETTY_INFO
Info log with details and colour.
This file contains the definition of the ThreadCapsule class, which manages a thread for user control...
Manages a thread for user controls.
const bool isRunning() const
Checks if the thread is running.
void toggleHelp()
Toggles the help state.
void toggleRecording()
Toggles the recording state.
const bool isLooping() const
Checks if looping is enabled.
void startThread()
Starts the thread to run the spamUserChoice function.
void toggleLooping()
Toggles the looping state.
void stopThread(const unsigned int delay=2)
Stops the thread safely.
void togglePlaying()
Toggles the playing state.
const bool isPlaying() const
Checks if playing is enabled.
void setUserChoice(const std::string &userChoice)
Processes the user choice.
const bool isHelp() const
Checks if help is enabled.
const bool isRecording() const
Checks if recording is enabled.
void setEcho(const bool echo)
Sets the echo state.
const std::string getInfo(const unsigned int indent=0) const
Dumps the current state of the variables for debugging purposes.
void setRecording(const bool recording)
Sets the recording state.
const bool hangUpTheCall() const
Checks if the call should be hung up.
void setPlaying(const bool playing)
Sets the playing state.
void setLooping(const bool looping)
Sets the looping state.
const bool isEcho() const
Checks if echo is enabled.
void toggleEcho()
Toggles the echo state.
void showPrompt() const
Displays the prompt to the user.
void setHelp(const bool help)
Sets the help state.
void spamUserChoice()
Continuously prompts the user for input and processes it.
std::ostream & operator<<(std::ostream &os, const ThreadCapsule &network)
Overloads the stream insertion operator for ThreadCapsule.
const std::string myToString(bool value)
Converts a boolean value to its string representation.