Only jumble and reveal the number of lines from the input stream that are equal to the

number of lines in the terminal window. After the jumble/reveal, print the remaining
characters.

	modified:   src/nms.c
This commit is contained in:
Brian Barto 2016-04-11 13:47:53 -04:00
parent 01721aca7c
commit 906fb5af2d

View File

@ -42,15 +42,16 @@ int main(void) {
// Seed my random number generator with the current time // Seed my random number generator with the current time
srand(time(NULL)); srand(time(NULL));
// TODO: what is the data piped is greater than the size of the terminal window?
// Geting input // Geting input
while ((c = getchar()) != EOF) { while ((c = getchar()) != EOF) {
if (c == NEWLINE) { if (c == NEWLINE) {
++y; ++y;
x = 1; x = 1;
} else if (isspace(c)) { } else if (isspace(c)) {
++x; if (++x > termSizeCols) {
++y;
x = 1;
}
} else { } else {
if (first) { if (first) {
list_pointer = malloc(sizeof(struct winpos)); list_pointer = malloc(sizeof(struct winpos));
@ -76,7 +77,10 @@ int main(void) {
list_pointer->s2_time = r_time > 1000 ? r_time_s : 0; list_pointer->s2_time = r_time > 1000 ? r_time_s : 0;
list_pointer->next = NULL; list_pointer->next = NULL;
++x; if (++x > termSizeCols) {
++y;
x = 1;
}
} }
} }
@ -93,7 +97,7 @@ int main(void) {
x = 0; x = 0;
while (x < (ls * 1000) / ms) { while (x < (ls * 1000) / ms) {
list_pointer = start; list_pointer = start;
while (list_pointer != NULL) { while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
printf("\033[%i;%iH%c", list_pointer->row, list_pointer->col, list_pointer->mask); printf("\033[%i;%iH%c", list_pointer->row, list_pointer->col, list_pointer->mask);
list_pointer->mask = getMaskChar(); list_pointer->mask = getMaskChar();
list_pointer = list_pointer->next; list_pointer = list_pointer->next;
@ -111,7 +115,7 @@ int main(void) {
while (loop) { while (loop) {
loop = false; loop = false;
list_pointer = start; list_pointer = start;
while (list_pointer != NULL) { while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
if (list_pointer->s1_time > 0) { if (list_pointer->s1_time > 0) {
loop = true; loop = true;
list_pointer->s1_time -= ms; list_pointer->s1_time -= ms;
@ -136,6 +140,26 @@ int main(void) {
printf("\n"); printf("\n");
// Printing remaining characters from list if we stopped short due to
// a terminal row limitation. i.e. the number of textual rows in the input
// stream were greater than the number of rows in the terminal.
int prevRow;
if (list_pointer != NULL) {
prevRow = list_pointer->row;
printf(KCYN);
while (list_pointer != NULL) {
while (list_pointer->row > prevRow) {
printf("\n");
++prevRow;
}
printf("\033[%i;%iH%c", termSizeRows, list_pointer->col, list_pointer->source);
list_pointer = list_pointer->next;
}
printf(KNRM);
printf("\n");
}
// Freeing the list. // Freeing the list.
list_pointer = start; list_pointer = start;
while (list_pointer != NULL) { while (list_pointer != NULL) {