Added option to change character used by bigclock

This commit is contained in:
catdotjs 2023-12-18 20:45:10 +02:00
parent dc7477951a
commit 8c7ad4ac97
6 changed files with 28 additions and 8 deletions

View File

@ -15,6 +15,9 @@
# Big clock formatting (see strftime specification) [allowed symbols 1-9,-,:] # Big clock formatting (see strftime specification) [allowed symbols 1-9,-,:]
#bigclock_format = %H:%M #bigclock_format = %H:%M
# Unicode Number of Big Block character. Supports UTF-16(Example █ = U+2588 = 0x2588 = 9608)
#bigclock_char = 9608
# The character used to mask the password # The character used to mask the password
#asterisk = * #asterisk = *

View File

@ -3,13 +3,8 @@
#define CLOCK_W 5 #define CLOCK_W 5
#define CLOCK_H 5 #define CLOCK_H 5
#if defined(__linux__) || defined(__FreeBSD__) #define X '.'
#define X 0x2593 #define _ 0
#define _ 0x0000
#else
#define X '#'
#define _ 0
#endif
#if CLOCK_W == 5 && CLOCK_H == 5 #if CLOCK_W == 5 && CLOCK_H == 5
@ -122,6 +117,9 @@ uint32_t CLOCK_D[] = {
#undef X #undef X
#undef _ #undef _
// I wish these were in a premade dictionary... Writing this felt like hell
uint32_t* CLOCK_CHARS[] = {CLOCK_0,CLOCK_1,CLOCK_2,CLOCK_3,CLOCK_4,CLOCK_5,CLOCK_6,CLOCK_7,CLOCK_8,CLOCK_9,CLOCK_S,CLOCK_E,CLOCK_D};
static inline uint32_t* CLOCK_N(char c) static inline uint32_t* CLOCK_N(char c)
{ {
switch(c) switch(c)

View File

@ -162,6 +162,7 @@ void config_load(const char *cfg_path)
{"asterisk", &config.asterisk, config_handle_char}, {"asterisk", &config.asterisk, config_handle_char},
{"bg", &config.bg, config_handle_u8}, {"bg", &config.bg, config_handle_u8},
{"bigclock", &config.bigclock, config_handle_bool}, {"bigclock", &config.bigclock, config_handle_bool},
{"bigclock_char", &config.bigclock_char, config_handle_u16},
{"bigclock_format", &config.bigclock_format, config_handle_str}, {"bigclock_format", &config.bigclock_format, config_handle_str},
{"blank_box", &config.blank_box, config_handle_bool}, {"blank_box", &config.blank_box, config_handle_bool},
{"blank_password", &config.blank_password, config_handle_bool}, {"blank_password", &config.blank_password, config_handle_bool},
@ -276,6 +277,7 @@ void config_defaults()
config.bg = 0; config.bg = 0;
config.bigclock = false; config.bigclock = false;
config.bigclock_format = NULL; config.bigclock_format = NULL;
config.bigclock_char = 0x2588;
config.blank_box = true; config.blank_box = true;
config.blank_password = false; config.blank_password = false;
config.clock = NULL; config.clock = NULL;

View File

@ -67,6 +67,7 @@ struct config
uint8_t bg; uint8_t bg;
bool bigclock; bool bigclock;
char* bigclock_format; char* bigclock_format;
uint32_t bigclock_char;
bool blank_box; bool blank_box;
bool blank_password; bool blank_password;
char* clock; char* clock;

View File

@ -70,6 +70,7 @@ void draw_init(struct term_buf* buf)
buf->box_chars.left = '|'; buf->box_chars.left = '|';
buf->box_chars.right = '|'; buf->box_chars.right = '|';
#endif #endif
bigclock_character_change();
} }
static void doom_free(struct term_buf* buf); static void doom_free(struct term_buf* buf);
@ -91,6 +92,20 @@ void draw_free(struct term_buf* buf)
} }
} }
void bigclock_character_change(){
for(int i = 0; i < sizeof(CLOCK_CHARS)/sizeof(CLOCK_CHARS[0]);i++){
uint32_t* curent_clock_char = CLOCK_CHARS[i];
for(int j = 0;j < 25;j++){
uint32_t current_char = curent_clock_char[j];
if(current_char!=0){
curent_clock_char[j] = config.bigclock_char;
}
}
}
}
void draw_box(struct term_buf* buf) void draw_box(struct term_buf* buf)
{ {
uint16_t box_x = (buf->width - buf->box_width) / 2; uint16_t box_x = (buf->width - buf->box_width) / 2;

View File

@ -88,5 +88,6 @@ bool cascade(struct term_buf* buf, uint8_t* fails);
void draw_bigclock(struct term_buf *buf); void draw_bigclock(struct term_buf *buf);
void draw_clock(struct term_buf *buf); void draw_clock(struct term_buf *buf);
void bigclock_character_change();
#endif #endif