Skip to content

Instantly share code, notes, and snippets.

@Kylmakalle
Last active December 15, 2017 11:22
Show Gist options
  • Save Kylmakalle/1fc1b17196ad3bfa83fb5e709aa132d5 to your computer and use it in GitHub Desktop.
Save Kylmakalle/1fc1b17196ad3bfa83fb5e709aa132d5 to your computer and use it in GitHub Desktop.
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
void DeleteLine(int delay=10000){
usleep(delay);
std::cout << "\033[A\033[2K";
}
std::string shifted_str(std::string s, int indent, int width){
std::string output;
for (int i = 0; i <= indent; i++)
output += " ";
output += s.substr(0, width - output.length());
return output;
}
void ticker(std::string s){
struct winsize size;
ioctl(STDOUT_FILENO,TIOCGWINSZ,&size);
for (int i = size.ws_col - 1; i > 0; i--){
//for (int i = 0; i < size.ws_col - 1; i++){ // From left to right
std::cout << shifted_str(s, i, size.ws_col) << std::endl;
DeleteLine(20000);
}
std::cout << s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment