Last active
August 29, 2015 14:16
-
-
Save spedru/ae464745b3b6b8fc60c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* cum pile with -std=c99 or -std=c11 */ | |
#define _POSIX_C_SOURCE 200809L | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <time.h> | |
static const struct timespec sleepytime = {0, 70000000}; | |
static const int bubble[] = {2, 3, 4, 5, 4, 3, 3, 2}; | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 2) | |
return !!fprintf(stderr, "You must provide at least something to bubble.\n"); | |
size_t len = 0; | |
for (int i = 1; i < argc; | |
len += 1 + strlen(argv[i++])); | |
char *buf = calloc(len, 1); | |
for (int i = 0; ++i < argc; | |
strcat(strcat(buf, argv[i]), " " + (i == argc - 1))); | |
buf[len - 1] = '\0'; | |
size_t rail = len * 2 + sizeof bubble / sizeof (int); | |
int *spaces = calloc(rail, sizeof (int)); | |
memcpy(spaces + len, bubble, sizeof bubble); | |
printf("\n\033[1A"); | |
for (size_t s = len + sizeof bubble / sizeof (int); s; s--) { | |
for (size_t t = 0; t < len; t++) | |
printf("%*c", spaces[s + t], buf[t]); | |
fflush(stdout); | |
nanosleep(&sleepytime, NULL); | |
putchar('\r'); | |
} | |
printf("\033[1B"); | |
free(buf); | |
free(spaces); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment