This commit is contained in:
0xf8 2023-06-03 15:35:34 -04:00
parent f5f7c50d7f
commit 15c1bfda44
Signed by: 0xf8
GPG Key ID: 446580D758689584
4 changed files with 15 additions and 49 deletions

View File

@ -1,7 +1,7 @@
OBJ = $(patsubst src/%.c,%.o,$(wildcard src/*.c))
HEADERS = $(wildcard src/*.h)
CC = clang
FLAGS = -std=c17 -O2 -pthread
FLAGS = -std=c17 -O3 -pthread
LIB = -lncurses -lnotcurses -lnotcurses-core
%.o: src/%.c $(HEADERS)

6
compile_commands.json Normal file
View File

@ -0,0 +1,6 @@
[
{
"arguments": [ "/usr/bin/gcc", "-c", "-o", "src/main.o", "src/main.c" ],
"file": "src/main.c"
}
]

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with thi
#include <notcurses/nckeys.h>
#include <notcurses/notcurses.h>
// 250000000ns = 250ms, 1/4s
enum {SECS_TO_SLEEP = 0, NSEC_TO_SLEEP = 250000000};
struct notcurses *_nc;
@ -217,7 +218,7 @@ struct bignumber_t *bignumber(int start, uint mimick) {
void drawbignumber(struct bignumber_t *bn, int sec, int startx, int starty, struct ncplane *plane) {
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 5; y++) {
struct string *padded_num = pad_int(bn->matrix[y][x], 2, 2);
struct string *padded_num = pad_int(bn->matrix[y][x]);
uint currentSec = (uint)sec == bn->matrix[y][x];
uint partOfMimick = mimicks[bn->mimick][y][x];
@ -245,53 +246,13 @@ void drawbignumber(struct bignumber_t *bn, int sec, int startx, int starty, stru
}
// pad_uint
struct string *pad_int(int n, uint pad, uint maxsize) {
struct string *str = (struct string *)malloc(sizeof (struct string) + 1);
maxsize++;
str->s = (char *)malloc((sizeof(char) * maxsize) + 1);
str->length = 0;
struct string *pad_int(int n) {
struct string *str = alloc_string(4);
snprintf(str->s, 4, "%02i%c", abs(n), 0);
memset(str->s, 0, maxsize);
return str;
};
// Figure out how many place values are in n
int _n = abs(n);
uint places = 1;
for (uint i = 0; i < pad; i++) {
if (_n >= 10) {
_n /= 10;
places++;
}
else break;
}
char *padding = (char *)malloc((sizeof(char) * pad) + 2);
for (uint i = 0; i < pad + 1; i++)
padding[i] = '0';
uint required_padding = pad - places;
if (required_padding > pad) required_padding = 0;
// Negative value
if (n < 0) {
required_padding++;
padding[0] = '-';
}
snprintf(str->s, maxsize, "%*.*s%i%c", 0, required_padding, padding, abs(n), 0);
free(padding);
for (uint i = 0; i < maxsize + 1; i++) {
if (str->s[i] == 0) {
str->length = i;
break;
}
}
return str;
}
// alloc_string
struct string *alloc_string(uint l) {

View File

@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License along with thi
#define __MAIN_H__
#include <locale.h>
#include <math.h>
#include <memory.h>
// #include <ncurses.h>
#include <notcurses/notcurses.h>
@ -45,7 +44,7 @@ struct string *alloc_string(uint l);
void free_string(struct string *s);
// pads a number with 0's
struct string *pad_int(int n, uint pad, uint maxsize);
struct string *pad_int(int n);
// this creates a bignumber_t
struct bignumber_t *bignumber(int start, uint mimick);