algorism: not sure what would be the Windows' equivalents of:
Code:
#include <sys/select.h>
#include <termios.h>
these would be required to define a windows version of reset_terminal_mode() in your program
my searches have taken me to Console WinEvents (Windows) but I'm not sure if I'm looking at the right places or, at the very least, in the right directions – apart from this outstanding (and it's a significant outstand no doubt), I've tried to incorporate some of your other suggestions and my current version is looking like this:
Code:
#include <iostream>
#include <string>
#include <future>
#include <chrono>
#include <conio.h>
int main()
{
using namespace std::chrono_literals;
std::string name{};
std::atomic<bool> ready{false};
auto tp = std::chrono::system_clock::now() + std::chrono::seconds(5);
std::future<void> f =
std::async(std::launch::async, [&name, &ready]()
{
std::cout << "enter your name \n";
getline(std::cin, name);
if(kbhit())
{
std::this_thread::sleep_for(5ms);
//small chance of false positive
ready = true;
}
std::cout << "well in time, your name is: " << name << "\n";
});
std::future_status s = f.wait_until(tp);
if(!ready)
{
//reset_terminal_mode();
}
if (s == std::future_status::ready)
{
f.get();
}
else
{
std::cout << "took too long, enter first name now \n";
std::string first_name{};
getline(std::cin, first_name);
std::cout << "now enter last name \n";
std::string last_name{};
std::cout << "full name is: " << first_name << " " << last_name << "\n";
}
}
If anybody has any Windows-based suggestions on how to wrest control back from console if no input within certain time I'd be very grateful. Thanks