Update 0.1
Signed-off-by: 0xf8 <0xf8.dev@proton.me>
This commit is contained in:
parent
aa4872c215
commit
88435ebe15
4
Makefile
4
Makefile
@ -1,8 +1,8 @@
|
|||||||
OBJ = $(patsubst src/%.c,%.o,$(wildcard src/*.c))
|
OBJ = $(patsubst src/%.c,%.o,$(wildcard src/*.c))
|
||||||
HEADERS = $(wildcard src/*.h)
|
HEADERS = $(wildcard src/*.h)
|
||||||
CC = clang
|
CC = clang
|
||||||
FLAGS = -std=c17 -O2
|
FLAGS = -std=c17 -O2 -pthread
|
||||||
LIB = -lncurses
|
LIB = -lncurses -lnotcurses -lnotcurses-core
|
||||||
|
|
||||||
%.o: src/%.c $(HEADERS)
|
%.o: src/%.c $(HEADERS)
|
||||||
$(CC) $(FLAGS) -c $< -o $@
|
$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
164
src/main.c
164
src/main.c
@ -13,15 +13,17 @@ You should have received a copy of the GNU General Public License along with thi
|
|||||||
|
|
||||||
#include "./main.h"
|
#include "./main.h"
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <stdlib.h>
|
#include <notcurses/nckeys.h>
|
||||||
|
#include <notcurses/notcurses.h>
|
||||||
|
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
enum {SECS_TO_SLEEP = 0, NSEC_TO_SLEEP = 40000000};
|
enum {SECS_TO_SLEEP = 0, NSEC_TO_SLEEP = 40000000};
|
||||||
|
|
||||||
|
struct notcurses *_nc;
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
endwin();
|
notcurses_stop(_nc);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint mimicks[10][5][3] = {
|
uint mimicks[10][5][3] = {
|
||||||
@ -96,72 +98,107 @@ uint mimicks[10][5][3] = {
|
|||||||
{ 1, 1, 1 } }
|
{ 1, 1, 1 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int rows;
|
||||||
|
int cols;
|
||||||
|
int midr;
|
||||||
|
int midc;
|
||||||
|
uint stop = false;
|
||||||
|
|
||||||
|
void *notcurses_thread(void *_) {
|
||||||
|
uint32_t input = 0;
|
||||||
|
ncinput ni;
|
||||||
|
|
||||||
|
while ((input = notcurses_get(_nc, 0, &ni)) != (uint32_t)-1) {
|
||||||
|
if (ni.evtype == NCTYPE_RELEASE) continue;
|
||||||
|
if (input == 'q') { stop = true; break; }
|
||||||
|
|
||||||
|
if (ni.id == NCKEY_RESIZE) {
|
||||||
|
unsigned dimx, dimy, oldx, oldy;
|
||||||
|
notcurses_term_dim_yx(_nc, &dimy, &dimx);
|
||||||
|
ncplane_dim_yx(notcurses_stdplane(_nc), &oldy, &oldx);
|
||||||
|
notcurses_refresh(_nc, &dimy, &dimx);
|
||||||
|
rows = dimy - 1;
|
||||||
|
cols = dimx - 1;
|
||||||
|
midr = rows / 2;
|
||||||
|
midc = cols / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// tests
|
// tests
|
||||||
struct timespec remaining, request = {SECS_TO_SLEEP, NSEC_TO_SLEEP};
|
struct timespec remaining, request = {SECS_TO_SLEEP, NSEC_TO_SLEEP};
|
||||||
|
|
||||||
initscr();
|
setlocale(LC_ALL, "C");
|
||||||
int rows = LINES - 1;
|
|
||||||
int cols = COLS - 1;
|
struct notcurses* nc = notcurses_init(NULL, stdout);
|
||||||
int midr = rows/2;
|
_nc = nc;
|
||||||
int midc = cols/2;
|
notcurses_enter_alternate_screen(nc);
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
|
|
||||||
start_color();
|
rows = LINES - 1;
|
||||||
init_pair(1,8,0);
|
cols = COLS - 1;
|
||||||
init_pair(2,7,0);
|
|
||||||
|
midr = rows / 2;
|
||||||
|
midc = cols / 2;
|
||||||
|
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
|
|
||||||
clear();
|
pthread_t thread_id;
|
||||||
|
pthread_create(&thread_id, NULL, notcurses_thread, NULL);
|
||||||
|
|
||||||
while (true) {
|
while (!stop) {
|
||||||
time_t *t = (time_t *)malloc(sizeof(time_t) + 1);
|
time_t *t = (time_t *)malloc(sizeof(time_t) + 1);
|
||||||
time(t);
|
time(t);
|
||||||
|
|
||||||
struct tm *lc = localtime(t);
|
struct tm *lc = localtime(t);
|
||||||
|
|
||||||
// hourul:minul:sec
|
// hourul:minul:sec
|
||||||
int hour = lc->tm_hour;
|
int hour = lc->tm_hour;
|
||||||
int hourl = hour % 10;
|
int hourl = hour % 10;
|
||||||
int houru = (hour - hourl) / 10;
|
int houru = (hour - hourl) / 10;
|
||||||
|
|
||||||
int min = lc->tm_min;
|
int min = lc->tm_min;
|
||||||
int minl = min % 10;
|
int minl = min % 10;
|
||||||
int minu = (min - minl) / 10;
|
int minu = (min - minl) / 10;
|
||||||
|
|
||||||
int sec = lc->tm_sec;
|
int sec = lc->tm_sec;
|
||||||
|
|
||||||
struct bignumber_t *bn_houru = bignumber(00, 0, houru);
|
struct bignumber_t *bn_houru = bignumber(00, 0, houru);
|
||||||
struct bignumber_t *bn_hourl = bignumber(15, 1, hourl);
|
struct bignumber_t *bn_hourl = bignumber(15, 1, hourl);
|
||||||
struct bignumber_t *bn_minu = bignumber(30, 2, minu);
|
struct bignumber_t *bn_minu = bignumber(30, 2, minu);
|
||||||
struct bignumber_t *bn_minl = bignumber(45, 3, minl);
|
struct bignumber_t *bn_minl = bignumber(45, 3, minl);
|
||||||
|
|
||||||
clear();
|
ncplane_erase(notcurses_stdplane(nc));
|
||||||
|
|
||||||
attron(A_DIM);
|
ncplane_set_fg_rgb(notcurses_stdplane(nc), 0x777777);
|
||||||
mvaddch(midr + 0, midc, '|');
|
ncplane_putchar_yx(notcurses_stdplane(nc), midr - 1, midc, '|');
|
||||||
mvaddch(midr + 1, midc, '|');
|
ncplane_putchar_yx(notcurses_stdplane(nc), midr + 0, midc, '|');
|
||||||
mvaddch(midr - 1, midc, '|');
|
ncplane_putchar_yx(notcurses_stdplane(nc), midr + 1, midc, '|');
|
||||||
attroff(A_DIM);
|
|
||||||
|
|
||||||
drawbignumber(bn_houru, sec, midc - 19, midr - 2);
|
drawbignumber(bn_houru, sec, midc - 19, midr - 2, notcurses_stdplane(nc));
|
||||||
drawbignumber(bn_hourl, sec, midc - 9, midr - 2);
|
drawbignumber(bn_hourl, sec, midc - 9, midr - 2, notcurses_stdplane(nc));
|
||||||
drawbignumber(bn_minu, sec, midc + 2, midr - 2);
|
drawbignumber(bn_minu, sec, midc + 2, midr - 2, notcurses_stdplane(nc));
|
||||||
drawbignumber(bn_minl, sec, midc + 12, midr - 2);
|
drawbignumber(bn_minl, sec, midc + 12, midr - 2, notcurses_stdplane(nc));
|
||||||
free(bn_houru);
|
free(bn_houru);
|
||||||
free(bn_hourl);
|
free(bn_hourl);
|
||||||
free(bn_minu);
|
free(bn_minu);
|
||||||
free(bn_minl);
|
free(bn_minl);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
notcurses_render(nc);
|
||||||
|
|
||||||
free(t);
|
free(t);
|
||||||
|
|
||||||
nanosleep(&request, &remaining);
|
nanosleep(&request, &remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_kill(thread_id, SIGKILL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,26 +216,37 @@ struct bignumber_t *bignumber(int start, uint index, uint mimick) {
|
|||||||
return bn;
|
return bn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawbignumber(struct bignumber_t *bn, int sec, int startx, int starty) {
|
void drawbignumber(struct bignumber_t *bn, int sec, int startx, int starty, struct ncplane *plane) {
|
||||||
for (int x = 0; x < 3; x++) {
|
for (int x = 0; x < 3; x++) {
|
||||||
for (int y = 0; y < 5; y++) {
|
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);
|
struct string *padded_num = pad_int(bn->matrix[y][x], 2, 2);
|
||||||
uint currentSec = (uint)sec == bn->matrix[y][x];
|
uint currentSec = (uint)sec == bn->matrix[y][x];
|
||||||
uint partOfMimick = mimicks[bn->mimick][y][x];
|
uint partOfMimick = mimicks[bn->mimick][y][x];
|
||||||
|
|
||||||
if (partOfMimick) attron(A_BOLD);
|
ncplane_set_bg_alpha(plane, NCALPHA_TRANSPARENT);
|
||||||
else attron(COLOR_PAIR(1));
|
ncplane_set_fg_alpha(plane, NCALPHA_OPAQUE);
|
||||||
|
|
||||||
if (currentSec) attron(A_REVERSE),attron(COLOR_PAIR(2));
|
uint32_t bg = ncplane_bg_rgb(plane);
|
||||||
|
uint32_t fg = ncplane_fg_rgb(plane);
|
||||||
|
if (partOfMimick) ncplane_set_fg_rgb(plane, 0xCCCCCC), ncplane_set_styles(plane, 0x0002u);
|
||||||
|
else ncplane_set_fg_rgb(plane, 0x555555);
|
||||||
|
|
||||||
addstr(padded_num->s);
|
if (currentSec) ncplane_set_bg_rgb(plane, 0xFFFFFF), ncplane_set_fg_rgb(plane, 0x333333), ncplane_set_bg_alpha(plane, NCALPHA_OPAQUE);
|
||||||
|
|
||||||
attroff(A_BOLD);
|
ncplane_set_styles(plane, ncplane_styles(plane));
|
||||||
attroff(A_REVERSE);
|
|
||||||
attroff(COLOR_PAIR(1));
|
ncplane_putstr_yx(plane, starty + y, startx + (x * 3), padded_num->s);
|
||||||
attroff(COLOR_PAIR(2));
|
|
||||||
|
|
||||||
|
ncplane_set_styles(plane, 0x0000);
|
||||||
|
ncplane_set_bg_rgb(plane, bg);
|
||||||
|
ncplane_set_fg_rgb(plane, fg);
|
||||||
|
ncplane_set_bg_alpha(plane, NCALPHA_TRANSPARENT);
|
||||||
|
ncplane_set_fg_alpha(plane, NCALPHA_OPAQUE);
|
||||||
|
// attroff(A_BOLD);
|
||||||
|
// attroff(A_REVERSE);
|
||||||
|
// attroff(COLOR_PAIR(1));
|
||||||
|
// attroff(COLOR_PAIR(2));
|
||||||
|
|
||||||
free_string(padded_num);
|
free_string(padded_num);
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,17 @@ You should have received a copy of the GNU General Public License along with thi
|
|||||||
#ifndef __MAIN_H__
|
#ifndef __MAIN_H__
|
||||||
#define __MAIN_H__
|
#define __MAIN_H__
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <ncurses.h>
|
// #include <ncurses.h>
|
||||||
#include <time.h>
|
#include <notcurses/notcurses.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
typedef unsigned long size;
|
typedef unsigned long size;
|
||||||
@ -49,6 +52,6 @@ struct string *pad_int(int n, uint pad, uint maxsize);
|
|||||||
struct bignumber_t *bignumber(int start, uint index, uint mimick);
|
struct bignumber_t *bignumber(int start, uint index, uint mimick);
|
||||||
|
|
||||||
// this draws a big number
|
// this draws a big number
|
||||||
void drawbignumber(struct bignumber_t *, int sec, int startx, int starty);
|
void drawbignumber(struct bignumber_t *, int sec, int startx, int starty, struct ncplane *place);
|
||||||
|
|
||||||
#endif // __MAIN_H__
|
#endif // __MAIN_H__
|
||||||
|
Loading…
Reference in New Issue
Block a user