big display kind of works

This commit is contained in:
Lexi Quinn 2023-04-11 14:06:42 +10:00
parent 65414c2d64
commit 9c7ccfe0b0
2 changed files with 65 additions and 33 deletions

View File

@ -348,7 +348,8 @@ int main(int argc, char *argv[])
int n, pid; int n, pid;
run = malloc(sizeof(struct run_event) * runMaxLength); run = malloc(sizeof(struct run_event) * runMaxLength);
//TODO: remove this file testing boilerplate //TODO: remove this file testing boilerplate
addFile(argv[1]); if (argc > 1)
addFile(argv[1]);
/* First call to socket() function */ /* First call to socket() function */
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);

View File

@ -7,13 +7,12 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <signal.h> #include <signal.h>
//Big numbies char numbermap[5][44] = {
char bignumbers[4][126] = { "xxx..x..xxx.xxx.x.x.xxx.xxx.xxx.xxx.xxx.....",
//char bignumbers[4][55] = { "x.x..x....x...x.x.x.x...x.....x.x.x.x.x.x...",
"▄▀▀▄ ▄█ ▄▀▀▄ ▄▀▀▄ ▄ █ █▀▀▀ ▄▀▀ ▀▀▀█ ▄▀▀▄ ▄▀▀▄ ", "x.x..x..xxx.xxx.xxx.xxx.xxx...x.xxx.xxx.....",
"█ █ █ ▄▀ ▄▀ █▄▄█ █▄▄ █▄▄ ▐▌ ▀▄▄▀ ▀▄▄█ ▀ ", "x.x..x..x.....x...x...x.x.x...x.x.x...x.x...",
"█ █ █ ▄▀ ▄ █ █ █ █ █ █ █ █ █ ▀ ", "xxx..x..xxx.xxx...x.xxx.xxx...x.xxx...x...x."
" ▀▀ ▀▀▀ ▀▀▀▀ ▀▀ ▀ ▀▀▀ ▀▀ ▀ ▀▀ ▀▀ ▀ "
}; };
struct termios base; struct termios base;
int fps = 60; int fps = 60;
@ -50,24 +49,53 @@ int timestringDigits(int ms)
return chars; return chars;
} }
//This function needs an x and y coordinate because the resulting string //Attempt 2 at thinking through how to print the big numbies
//is supposed to be printed across 4 rows so it cant really just return the void printbig(int x, int y, int ms)
//resulting string
void printbigtimestring(int ms, int x, int y)
{ {
//convert the single cell per character string length into the same char small[13];
//thing for the big time string, it cant just be a simple multiplication timestring(&small, ms);
//because the : and . digits arent as wide as the numbers if (w < strlen(small)) {
printf("2smol\n");
//Example string, printing a blank timer with all digits at x=65, y=40. return;
}
//\033[40;65H▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ int bigstringw = 42; //Minimum width and height the big timer string
//\033[41;65H█ █ █ █ █ █ ▀ █ █ █ █ ▀ █ █ █ █ █ █ █ █ int bigstringh = 5; //bigger sizes are just multiples of these numbers.
//\033[42;65H█ █ █ █ █ █ ▀ █ █ █ █ ▀ █ █ █ █ █ █ █ █ int bigstrings = 1;
//\033[43;65H ▀▀ ▀▀ ▀▀ ▀▀ ▀▀ ▀▀ ▀▀ ▀ ▀▀ ▀▀ x = (w - (bigstringw - 1 * bigstrings)) / 2; //theres a -1 because theres extra whitespace on the last printed digit
y = (h - (bigstringh * bigstrings)) / 2;
char buffer[256]; for (int sy = 0; sy < 5; sy++) { //for every row
printf("\033[%d;%dH", y + sy, x); //go to position
for (int cc = 0; cc < 12; cc++) { //then, for every character
int c = small[cc]; //check what character we're on
if (c >= 48 && c <= 57) { //if its a number, print 4 pixels
for (int xx = 0; xx < 4; xx++) {
int xxx = c - 48;
if (numbermap[sy][(xxx * 4) + xx] == 'x')
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
if (numbermap[sy][(xxx * 4) + xx] == '.')
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
}
}
if (c == 46 || c == 58) { //if its punctuation, print 2 pixels
for (int xx = 0; xx < 2; xx++) {
if (c == 46) {
if (numbermap[sy][42 + xx] == 'x')
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
if (numbermap[sy][42 + xx] == '.')
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
}
if (c == 58) {
if (numbermap[sy][40 + xx] == 'x')
printf("\033[48;2;%d;%d;%dm ", f.r, f.g, f.b);
if (numbermap[sy][40 + xx] == '.')
printf("\033[48;2;%d;%d;%dm ", b.r, b.g, b.b);
}
}
}
}
}
printf("\n");
//printf("\033[%d;%dH%s\n", y, x, small + (12 - timestringDigits(time)));
} }
void timestring(char *str, int ms) void timestring(char *str, int ms)
@ -123,7 +151,8 @@ void processColorString(struct color *c, char* s)
int compcount = 0; int compcount = 0;
int colorcompsdone = 0; int colorcompsdone = 0;
//TODO: if we know the length now that we're not doing fgetc we dont //TODO: if we know the length now that we're not doing fgetc we dont
//need a while loop; convert to for loop //need a while loop; convert to for loop.
//Why? what makes a for loop better than a while loop?
while (1) { while (1) {
char x = s[i++]; char x = s[i++];
if (x >= 48 && x <= 57) { if (x >= 48 && x <= 57) {
@ -164,7 +193,7 @@ int main (int argc, char *argv[])
char ti[13]; char ti[13];
//Request foreground color from config file //Request foreground color from config file
fp = popen("./quest-log foreground", "r"); fp = popen("./result/bin/quest-log foreground", "r");
fgets(path, sizeof(path), fp); fgets(path, sizeof(path), fp);
if (strcmp(path, "DATA NOT PRESENT")) if (strcmp(path, "DATA NOT PRESENT"))
processColorString(&f, path); processColorString(&f, path);
@ -172,7 +201,7 @@ int main (int argc, char *argv[])
pclose(fp); pclose(fp);
//Request background color from config file //Request background color from config file
fp = popen("./quest-log background", "r"); fp = popen("./result/bin/quest-log background", "r");
fgets(path, sizeof(path), fp); fgets(path, sizeof(path), fp);
if (strcmp(path, "DATA NOT PRESENT")) if (strcmp(path, "DATA NOT PRESENT"))
processColorString(&b, path); processColorString(&b, path);
@ -184,21 +213,23 @@ int main (int argc, char *argv[])
if (!strcmp(argv[i], "-fps")) if (!strcmp(argv[i], "-fps"))
fps = atoi(argv[i + 1]); fps = atoi(argv[i + 1]);
} }
while (1) { while (1) {
int time = 0; int time = 0;
fp = popen("./quest-log time", "r"); fp = popen("./result/bin/quest-log time", "r");
if (fp == NULL) { if (fp == NULL) {
printf("Failed to run command\n"); printf("Failed to run command\n");
exit(1); exit(1);
} }
//TODO: why is this a while loop?
while (fgets(path, sizeof(path), fp) != NULL) { while (fgets(path, sizeof(path), fp) != NULL) {
time = atoi(path); time = atoi(path);
printf("\033[2J\n");
timestring(&ti, time);
printf("%s\n", ti + (12 - timestringDigits(time)));
} }
pclose(fp); pclose(fp);
printf("\033[2J\n");
//timestring(&ti, time);
//printf("%s\n", ti + (12 - timestringDigits(time)));
printbig(3, 4, time);
usleep(1000000 / fps); usleep(1000000 / fps);
} }
} }