I have a function for scrolling text left to right in an NCurses interface, but it depends upon a timer every 500 ms or so to properly write out a new character in front and delete the previous character behind. Here is the code:
void GekkoFyre::TuiHangouts::gui_scrollText(WINDOW *display, const char *msg,
const int &msgPosY)
{
size_t maxX = getmaxx(display);
size_t msgLen = strlen(msg);
short origPosY = 0;
short origPosX = 0;
getyx(display, origPosY, origPosX); // Obtain the original cursor position
if (msgLen > maxX) {
// size_t diff = (msgLen - maxX);
size_t i = 0;
for (i = maxX; i < msgLen; ++i) {
// Scroll the message from left to right, then vice versa, so that it fits within the
// designated window.
move(msgPosY, 0);
clrtoeol(); // Delete just the given line, <http://stackoverflow.com/questions/5072881/how-to-clear-a-specific-line-with-ncurses>
move(origPosY, origPosX); // Go back to the original cursor position
std::string tmp((msgLen - i), msg[(msgLen - i)]);
wattron(display, A_REVERSE); // Highlight selection
mvwaddstr(display, msgPosY, 0, tmp.c_str());
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
}
I honestly have no idea if this works because I've been unable to get it to work. But is there a timer just like, std::this_thread::sleep_for(std::chrono::milliseconds(500));
, that you can use within a function but is asynchronous? That would be beautiful! I've done some research and come across std::async and std::thread, but they depend upon being external to the function.
Any help would be greatly appreciated, thank you.