Browse Source

more compatible w escape codes, has vertical variation now

dev
alistair 4 years ago
parent
commit
13b82658fe
  1. 13
      Makefile
  2. 31
      colcat.c

13
Makefile

@ -1,5 +1,12 @@ @@ -1,5 +1,12 @@
default: colcat.c colcat.h
default: colcat.c
gcc -c colcat.c -o bin/colcat.o
gcc -c c-colours/colours.c -o bin/colours.o
gcc -c c-colours/colours.c -o bin/colours.o
gcc -lm bin/colcat.o bin/colours.o -o bin/colcat
debug: colcat.c
gcc -g -c colcat.c -o bin/colcat.o
gcc -g -c c-colours/colours.c -o bin/colours.o
gcc -g -lm bin/colcat.o bin/colours.o -o bin/colcat
clean:
rm bin/*

31
colcat.c

@ -7,9 +7,10 @@ @@ -7,9 +7,10 @@
/*
* Basic Settings
*/
int rainbow_len = 80; // how many characters long is one full rainbow (360deg)
int rainbow_len = 90; // how many characters long is one full rainbow (360deg)
int col_change; // how many degrees between colours in the rainbow
int col_dist; // how many characters per colour in output
int frequency = 1; // how many degrees to rotate start point on new line
struct colour* colours; // the rainbow
int num_colours; // the length of the rainbow
@ -26,17 +27,30 @@ void print_next_colour(int current) { @@ -26,17 +27,30 @@ void print_next_colour(int current) {
int display(FILE *file) {
char c = fgetc(file);
int start = 0;
int counter = 0;
bool in_escape = false;
while (c != EOF) {
if (c == '\n') {
counter = 0;
counter = (start += frequency);
}
print_next_colour(counter);
printf("%c", c);
if (c == '\033') {
in_escape = true;
} else if (c == 'm' && in_escape) {
in_escape = false;
c = fgetc(file);
continue;
}
if (!in_escape) {
print_next_colour(counter);
}
putc(c, stdout);
counter++;
c = fgetc(file);
}
counter++;
return 0;
}
@ -62,7 +76,7 @@ int generate_rainbow() { @@ -62,7 +76,7 @@ int generate_rainbow() {
col_change = 1;
}
col_dist = rainbow_len / num_colours;
col_dist = (rainbow_len) / (num_colours);
colours = calloc(num_colours, sizeof(struct colour));
struct colour c;
c.h = 0;
@ -80,13 +94,16 @@ int generate_rainbow() { @@ -80,13 +94,16 @@ int generate_rainbow() {
int main(int argc, char** argv) {
int opt;
int optcount = 0;
while ((opt = getopt(argc, argv, "l:")) != -1) {
while ((opt = getopt(argc, argv, "l:f:")) != -1) {
optcount++;
if (opt == 'l') {
optcount++;
rainbow_len = atoi(optarg);
} else if (opt == 'f') {
optcount++;
frequency = atoi(optarg);
} else {
printf("Usage: colcat -l [rainbow length]");
printf("Usage: colcat -l [rainbow length] -f [frequency]");
}
}

Loading…
Cancel
Save