2023-02-25 22:36:52 +05:30
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2022 g.uwu@tutanota.com
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-02-25 22:36:52 +05:30
|
|
|
#include "./main.h"
|
|
|
|
#include <curses.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
|
|
|
|
|
|
|
enum {SECS_TO_SLEEP = 0, NSEC_TO_SLEEP = 40000000};
|
|
|
|
|
|
|
|
void cleanup() {
|
|
|
|
endwin();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint mimicks[10][5][3] = {
|
|
|
|
// 0
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 1
|
|
|
|
{ { 1, 1, 0 },
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 2
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 3
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 4
|
|
|
|
{ { 1, 0, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 0, 0, 1 } },
|
|
|
|
|
|
|
|
// 5
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 6
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 7
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 0, 1, 1 },
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, 1, 0 } },
|
|
|
|
|
|
|
|
// 8
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 } },
|
|
|
|
|
|
|
|
// 9
|
|
|
|
{ { 1, 1, 1 },
|
|
|
|
{ 1, 0, 1 },
|
|
|
|
{ 1, 1, 1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 1, 1, 1 } }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
// tests
|
|
|
|
struct timespec remaining, request = {SECS_TO_SLEEP, NSEC_TO_SLEEP};
|
|
|
|
|
2023-02-25 22:36:52 +05:30
|
|
|
initscr();
|
2023-02-25 22:36:52 +05:30
|
|
|
int rows = LINES - 1;
|
|
|
|
int cols = COLS - 1;
|
|
|
|
int midr = rows/2;
|
|
|
|
int midc = cols/2;
|
|
|
|
atexit(cleanup);
|
|
|
|
|
|
|
|
start_color();
|
|
|
|
init_pair(1,8,0);
|
|
|
|
init_pair(2,7,0);
|
|
|
|
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// TODO: add framelimiting
|
|
|
|
while (true) {
|
|
|
|
time_t *t = (time_t *)malloc(sizeof(time_t) + 1);
|
|
|
|
time(t);
|
|
|
|
|
|
|
|
struct tm *lc = localtime(t);
|
|
|
|
|
|
|
|
// hourul:minul:sec
|
|
|
|
int hour = lc->tm_hour;
|
|
|
|
int hourl = hour % 10;
|
|
|
|
int houru = (hour - hourl) / 10;
|
|
|
|
|
|
|
|
int min = lc->tm_min;
|
|
|
|
int minl = min % 10;
|
|
|
|
int minu = (min - minl) / 10;
|
|
|
|
|
|
|
|
int sec = lc->tm_sec;
|
|
|
|
|
|
|
|
struct bignumber_t *bn_houru = bignumber(00, 0, houru);
|
|
|
|
struct bignumber_t *bn_hourl = bignumber(15, 1, hourl);
|
|
|
|
struct bignumber_t *bn_minu = bignumber(30, 2, minu);
|
|
|
|
struct bignumber_t *bn_minl = bignumber(45, 3, minl);
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
attron(A_DIM);
|
|
|
|
mvaddch(midr + 0, midc, '|');
|
|
|
|
mvaddch(midr + 1, midc, '|');
|
|
|
|
mvaddch(midr - 1, midc, '|');
|
|
|
|
attroff(A_DIM);
|
|
|
|
|
|
|
|
drawbignumber(bn_houru, sec, midc - 19, midr - 2);
|
|
|
|
drawbignumber(bn_hourl, sec, midc - 9, midr - 2);
|
|
|
|
drawbignumber(bn_minu, sec, midc + 2, midr - 2);
|
|
|
|
drawbignumber(bn_minl, sec, midc + 12, midr - 2);
|
|
|
|
free(bn_houru);
|
|
|
|
free(bn_hourl);
|
|
|
|
free(bn_minu);
|
|
|
|
free(bn_minl);
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
nanosleep(&request, &remaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bignumber_t *bignumber(int start, uint index, uint mimick) {
|
|
|
|
struct bignumber_t *bn = (struct bignumber_t *)malloc(sizeof(struct bignumber_t) + 1);
|
|
|
|
|
|
|
|
uint i = start;
|
|
|
|
for (int x = 0; x < 3; x++)
|
|
|
|
for (int y = 0; y < 5; y++)
|
|
|
|
bn->matrix[y][x] = i, i++;
|
|
|
|
|
|
|
|
bn->index = index;
|
|
|
|
bn->mimick = mimick;
|
|
|
|
|
|
|
|
return bn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawbignumber(struct bignumber_t *bn, int sec, int startx, int starty) {
|
|
|
|
for (int x = 0; x < 3; x++) {
|
|
|
|
for (int y = 0; y < 5; y++) {
|
|
|
|
move(starty + y, startx + (x * 3));
|
|
|
|
|
|
|
|
struct string *padded_num = pad_int(bn->matrix[y][x], 2, 2);
|
|
|
|
uint currentSec = (uint)sec == bn->matrix[y][x];
|
|
|
|
uint partOfMimick = mimicks[bn->mimick][y][x];
|
|
|
|
|
|
|
|
if (partOfMimick) attron(A_BOLD);
|
|
|
|
else attron(COLOR_PAIR(1));
|
|
|
|
|
|
|
|
if (currentSec) attron(A_REVERSE),attron(A_BOLD),attron(COLOR_PAIR(2));
|
|
|
|
|
|
|
|
addstr(padded_num->s);
|
|
|
|
|
|
|
|
attroff(A_BOLD);
|
|
|
|
attroff(A_REVERSE);
|
|
|
|
attroff(COLOR_PAIR(1));
|
|
|
|
attroff(COLOR_PAIR(2));
|
|
|
|
|
|
|
|
free_string(padded_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
memset(str->s, 0, maxsize);
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
struct string *s = (struct string *)malloc(sizeof(struct string) + 1);
|
|
|
|
s->s = (char *)malloc(l + 1);
|
|
|
|
s->length = l;
|
|
|
|
|
|
|
|
memset(s->s, 0, l);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// free_string
|
|
|
|
void free_string(struct string *s) {
|
|
|
|
free(s->s);
|
|
|
|
free(s);
|
|
|
|
}
|