From c8bb1517c55d8e6b28fd6e3b7c2d65f8e57a1d83 Mon Sep 17 00:00:00 2001 From: Kalzu Rekku Date: Mon, 27 Jan 2025 12:10:57 +0200 Subject: [PATCH] Way better active alarm display. Snooze and dismiss are still wierd. --- alert_api/ncurses_ui_draw.py | 61 +++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/alert_api/ncurses_ui_draw.py b/alert_api/ncurses_ui_draw.py index 0e6b2e5..409f8f3 100644 --- a/alert_api/ncurses_ui_draw.py +++ b/alert_api/ncurses_ui_draw.py @@ -28,12 +28,40 @@ def _draw_error(stdscr, error_message): stdscr.attroff(curses.color_pair(3) | curses.A_BOLD) def _draw_active_alarms(stdscr, context): - """Draw the active alarms screen""" + """Draw the active alarms""" _init_colors() height, width = stdscr.getmaxyx() + current_time = datetime.now() + # Draw the main clock (original position) + time_str = current_time.strftime("%H:%M:%S") + digit_width = 14 + total_width = digit_width * len(time_str) + start_x = (width - total_width) // 2 + start_y = (height - 7) // 2 - 4 # Original position from _draw_main_clock + + # Draw blinking dot + if int(current_time.timestamp()) % 2 == 0: + stdscr.attron(curses.color_pair(1)) + stdscr.addstr(start_y - 1, start_x + total_width - 2, "•") + stdscr.attroff(curses.color_pair(1)) + + # Green color for big time + stdscr.attron(curses.color_pair(1)) + for i, digit in enumerate(time_str): + _draw_big_digit(stdscr, start_y, start_x + i * digit_width, digit) + stdscr.attroff(curses.color_pair(1)) + + # Draw date (as in main clock) + date_str = current_time.strftime("%Y-%m-%d") + date_x = width // 2 - len(date_str) // 2 + date_y = height // 2 + 4 + stdscr.attron(curses.color_pair(2)) + stdscr.addstr(date_y, date_x, date_str) + stdscr.attroff(curses.color_pair(2)) + + # Get active alarm info active_alarms = context.get('active_alarms', {}) - if not active_alarms: return @@ -41,15 +69,26 @@ def _draw_active_alarms(stdscr, context): alarm_id = list(active_alarms.keys())[0] alarm_info = active_alarms[alarm_id] alarm_config = alarm_info['config'] - - # Draw alarm details - stdscr.addstr(height // 2 - 2, width // 2 - 10, "ALARM TRIGGERED") - stdscr.addstr(height // 2, width // 2 - len(alarm_config.get('name', 'Unnamed Alarm'))//2, - alarm_config.get('name', 'Unnamed Alarm')) - - # Time info - time_str = alarm_config.get('time', 'Unknown Time') - stdscr.addstr(height // 2 + 2, width // 2 - len(time_str)//2, time_str) + + # Format alarm info + alarm_name = alarm_config.get('name', 'Unnamed Alarm') + alarm_time = alarm_config.get('time', 'Unknown Time') + #snooze_count = alarm_info.get('snooze_count', 0) + + # Draw alarm info under the clock + info_y = start_y + 8 # Position below the clock + #alarm_str = f"[ {alarm_name} - {alarm_time} - Snoozed: {snooze_count}x ]" + alarm_str = f"[ {alarm_name} - {alarm_time} ]" + alarm_x = max(0, width // 2 - len(alarm_str) // 2) + alarm_y = date_y - 2 # Just above the date + + # Center the alarm info + info_x = max(0, width // 2 - len(alarm_str) // 2) + + # Draw with green color + stdscr.attron(curses.color_pair(1)) + stdscr.addstr(alarm_y, alarm_x, alarm_str) + stdscr.attroff(curses.color_pair(1)) # Instructions stdscr.addstr(height - 2, width // 2 - 15, "S: Snooze D: Dismiss")