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,6 +348,7 @@ int main(int argc, char *argv[])
int n, pid;
run = malloc(sizeof(struct run_event) * runMaxLength);
//TODO: remove this file testing boilerplate
if (argc > 1)
addFile(argv[1]);
/* First call to socket() function */

View File

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