From ff528b997eb3db3269a5a748532b51c7adbbb094 Mon Sep 17 00:00:00 2001 From: q Date: Thu, 20 Jun 2024 10:55:32 +0300 Subject: [PATCH] new and improved --- bin/clockcurses | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/clockcurses b/bin/clockcurses index 77deed2..7e7be3c 100755 --- a/bin/clockcurses +++ b/bin/clockcurses @@ -22,7 +22,7 @@ ascii_digits = { ":": " . . ", } - +# fmt: off fancy_digits = { "0": ("▗▄▖" "█ █" @@ -78,7 +78,7 @@ fancy_digits = { "▝▀▘"), ":": " ▗ ▝ ", } - +# fmt: on # ~ ░ ▒ ▓ @@ -158,16 +158,17 @@ def drawdigital(win, y, x, t, ascii=False): drawdigit(win, y, x + 4 * c, hrs[c], ascii=ascii) -def drawalarms(stdscr, y, x, t, alarms): +def drawalarms(stdscr, y, x, t, alarms, tick_tock): ya = y now = 100 * t.tm_hour + t.tm_min is_alarm = False for alarm in alarms: if alarm["hstart"] <= now and alarm["hend"] >= now: - if t.tm_sec % 2 == 0: - color = curses.color_pair(4) + curses.A_BOLD + curses.A_REVERSE - else: - color = curses.color_pair(2) + curses.A_BOLD + color = ( + curses.color_pair(4) + curses.A_BOLD + curses.A_REVERSE + if tick_tock + else curses.color_pair(2) + curses.A_BOLD + ) is_alarm = True else: color = curses.color_pair(7) @@ -237,6 +238,8 @@ def main(): curses.init_pair(i + 1, i, -1) start_t = time.time() is_alarm = False + t_old = time.localtime(time.time()) + tick_tock = False try: # rows,columns = termsize() curses.cbreak() @@ -258,15 +261,18 @@ def main(): alphas = math.pi * (f + t_s) / 30.0 alpham = math.pi * t_m / 30.0 + alphas / 60.0 alphah = math.pi * t_h / 6.0 + alpham / 12.0 - if t_s == 0: + if t_old.tm_min != t.tm_min: # clear once a minute stdscr.clear() + + tick_tock = not tick_tock if options.refresh > 1 else t.tm_sec % 2 + drawcircle( stdscr, cy, cx, r / 2, - attr=curses.color_pair(2) + curses.A_BOLD if is_alarm and t_s % 2 == 0 else curses.color_pair(1), + attr=curses.color_pair(2) + curses.A_BOLD + curses.A_BLINK if is_alarm else curses.color_pair(1), ) if options.seconds: drawline(stdscr, cy, cx, alphas, 1, r / 2, "■", curses.color_pair(2)) @@ -281,7 +287,7 @@ def main(): drawdigital(stdscr, 7, 1, t, options.ascii) else: drawdigital(stdscr, 1, 1, t, options.ascii) - is_alarm = drawalarms(stdscr, 1, 35, t, alarms) + is_alarm = drawalarms(stdscr, 1, 35, t, alarms, tick_tock) stdscr.refresh() userinput = readinput(stdscr, options.refresh) if userinput == "x": @@ -294,6 +300,7 @@ def main(): drawline(stdscr, cy, cx, alphas, 1, r / 2, " ", curses.color_pair(2)) drawline(stdscr, cy, cx, alpham, 1, int(round(r * 0.9) / 2), " ", curses.color_pair(3)) drawline(stdscr, cy, cx, alphah, 1, int(round(r * 0.6) / 2), " ", curses.color_pair(7)) + t_old = t except KeyboardInterrupt: curses.nocbreak()