From 9cd1b70d997453fd06ca50644c400d028a51b525 Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Fri, 17 Oct 2025 22:32:58 +0200 Subject: [PATCH 1/7] add alarms-list output formats --- khal/khalendar/event.py | 8 ++++++++ khal/utils.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 3af1531cd..24d68caaa 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -722,6 +722,14 @@ def attributes( attributes["repeat-symbol"] = self._recur_str attributes["repeat-pattern"] = self.recurpattern attributes["alarm-symbol"] = self._alarm_str + attributes["alarms-list"] = [ + { + "delta": alarm[0].total_seconds(), + "description": str(alarm[1]), + "delta-formatted": timedelta2str(alarm[0]) + } + for alarm in self.alarms + ] attributes["status-symbol"] = self._status_str attributes["partstat-symbol"] = self._partstat_str attributes["title"] = self.summary diff --git a/khal/utils.py b/khal/utils.py index 4e7d4e70f..597fd2d57 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -197,6 +197,11 @@ def fmt(rows): if 'calendar-color' in row: row['calendar-color'] = get_color(row['calendar-color']) + if 'alarms-list' in row and isinstance(row['alarms-list'], list): + row['alarms-list'] = ", ".join( + alarm['description']+"@"+alarm['delta-formatted'] for alarm in row['alarms-list'] + ) + s = format_string.format(**row) if colors: @@ -220,6 +225,7 @@ def fmt(rows): 'end-date-full', 'end-date-long-full', 'end-time-full', 'duration-full', 'start-style', 'end-style', 'to-style', 'start-end-time-style', 'end-necessary', 'end-necessary-long', 'repeat-symbol', 'repeat-pattern', + 'alarm-symbol', 'alarms-list', 'title', 'organizer', 'description', 'location', 'all-day', 'categories', 'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled'] From 46bc15c6c38f1871965308677135251bef4f4ddb Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:37:45 +0200 Subject: [PATCH 2/7] add tests --- tests/cli_test.py | 25 +++++++++++++++++++++++++ tests/event_test.py | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/cli_test.py b/tests/cli_test.py index 5300a3207..882c61d08 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -475,6 +475,31 @@ def test_list_json(runner): assert result.output.startswith(expected) +def test_list_alarms(runner): + runner = runner(days=2) + now = dt.datetime.now().strftime('%d.%m.%Y') + runner.invoke( + main_khal, + f"new {now} 18:00 myevent --alarms -15m,1h".split()) + args = ['list', '--format', '{alarms-list}', '--day-format', ''] + result = runner.invoke(main_khal, args) + assert not result.exception + assert result.output.strip() == '@15m, @-1h' + + +def test_list_alarms_json(runner): + runner = runner() + now = dt.datetime.now().strftime('%d.%m.%Y') + runner.invoke( + main_khal, + f"new {now} 18:00 myevent --alarms 15m,1h".split()) + args = ['list', '--json', 'alarms-list'] + result = runner.invoke(main_khal, args) + expected = '[{"alarms-list": [{"delta": -900.0, "description": "", "delta-formatted": "-15m"}, {"delta": -3600.0, "description": "", "delta-formatted": "-1h"}]}]' + assert not result.exception + assert result.output.startswith(expected) + + def test_search(runner): runner = runner(days=2) now = dt.datetime.now().strftime('%d.%m.%Y') diff --git a/tests/event_test.py b/tests/event_test.py index 8255a76bf..d161e95bc 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -538,6 +538,27 @@ def test_event_alarm(): assert event.alarms == [(dt.timedelta(-1, 82800), vText('new event'))] +def test_event_alarm_list(): + """test the content of `alarms-list` attribute""" + event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS) + assert event.alarms == [] + event.update_alarms([(dt.timedelta(minutes=30), 'alarm 1'), + (-dt.timedelta(hours=1, minutes=30), 'alarm 2')]) + attributes = event.attributes(dt.date.today()) + assert attributes['alarms-list'] == [ + {'delta': 1800.0, 'description': 'alarm 1', 'delta-formatted': '30m'}, + {'delta': -5400.0, 'description': 'alarm 2', 'delta-formatted': '-1h -30m'} + ] + + +def test_event_no_alarms_list(): + """test that `alarms-list` is empty for an event with no alarms""" + event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS) + assert event.alarms == [] + attributes = event.attributes(dt.date.today()) + assert attributes['alarms-list'] == [] + + def test_event_attendees(): event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS) assert event.attendees == "" From f84b291184764c4819390a6ceebb6885b85958a8 Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:45:32 +0200 Subject: [PATCH 3/7] add docs and no alarm-symbol in json --- doc/source/usage.rst | 5 ++++- khal/utils.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/source/usage.rst b/doc/source/usage.rst index c07ddf390..0d6ec29cb 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -115,6 +115,9 @@ Several options are common to almost all of :program:`khal`'s commands alarm-symbol An alarm symbol (alarm clock) if the event has at least one alarm. + alarms-list + A comma-separated list of alarms for the event (e.g., `alarm1@-15m, getready@-1h`). + location The event location. @@ -222,7 +225,7 @@ Several options are common to almost all of :program:`khal`'s commands end-date-long, end-time, start-full, start-long-full, start-date-full, start-date-long-full, start-time-full, end-full, end-long-full, end-date-full, end-date-long-full, - end-time-full, repeat-symbol, location, calendar, + end-time-full, repeat-symbol, alarms-list, location, calendar, calendar-color, start-style, to-style, end-style, start-end-time-style, end-necessary, end-necessary-long, status, cancelled, organizer, url, duration, duration-full, diff --git a/khal/utils.py b/khal/utils.py index 597fd2d57..debd8cf88 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -225,7 +225,7 @@ def fmt(rows): 'end-date-full', 'end-date-long-full', 'end-time-full', 'duration-full', 'start-style', 'end-style', 'to-style', 'start-end-time-style', 'end-necessary', 'end-necessary-long', 'repeat-symbol', 'repeat-pattern', - 'alarm-symbol', 'alarms-list', + 'alarms-list', 'title', 'organizer', 'description', 'location', 'all-day', 'categories', 'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled'] From 7b801dccd251a69022b9d4b54d4b0452f3878e9f Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Mon, 20 Oct 2025 14:29:46 +0200 Subject: [PATCH 4/7] fix-precommit-ci attempt 1 --- khal/khalendar/event.py | 4 ++-- khal/utils.py | 3 ++- tests/cli_test.py | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 24d68caaa..d1b666dd0 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -25,7 +25,7 @@ import datetime as dt import logging import os -from typing import Callable, Optional, Union +from typing import Any, Callable, Optional, Union import icalendar import icalendar.cal @@ -603,7 +603,7 @@ def attributes( """ env = env or {} - attributes = {} + attributes: dict[str, Any] = {} if isinstance(relative_to, tuple): relative_to_start, relative_to_end = relative_to else: diff --git a/khal/utils.py b/khal/utils.py index debd8cf88..63f5bda1f 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -199,7 +199,8 @@ def fmt(rows): if 'alarms-list' in row and isinstance(row['alarms-list'], list): row['alarms-list'] = ", ".join( - alarm['description']+"@"+alarm['delta-formatted'] for alarm in row['alarms-list'] + alarm['description']+"@"+alarm['delta-formatted'] + for alarm in row['alarms-list'] ) s = format_string.format(**row) diff --git a/tests/cli_test.py b/tests/cli_test.py index 882c61d08..bc43207c5 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -495,7 +495,10 @@ def test_list_alarms_json(runner): f"new {now} 18:00 myevent --alarms 15m,1h".split()) args = ['list', '--json', 'alarms-list'] result = runner.invoke(main_khal, args) - expected = '[{"alarms-list": [{"delta": -900.0, "description": "", "delta-formatted": "-15m"}, {"delta": -3600.0, "description": "", "delta-formatted": "-1h"}]}]' + expected = '[{"alarms-list": [\ + {"delta": -900.0, "description": "", "delta-formatted": "-15m"},\ + {"delta": -3600.0, "description": "", "delta-formatted": "-1h"}\ + ]}]' assert not result.exception assert result.output.startswith(expected) From ca9ef80931a7fba2eb25635580fa0aa8f8384108 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 09:12:45 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- khal/khalendar/event.py | 5 +++-- khal/utils.py | 11 +++++------ tests/cli_test.py | 18 +++++++----------- tests/event_test.py | 17 +++++++++-------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 8505b1953..f660b4d44 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -25,7 +25,8 @@ import datetime as dt import logging import os -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any import icalendar import icalendar.cal @@ -738,7 +739,7 @@ def attributes( { "delta": alarm[0].total_seconds(), "description": str(alarm[1]), - "delta-formatted": timedelta2str(alarm[0]) + "delta-formatted": timedelta2str(alarm[0]), } for alarm in self.alarms ] diff --git a/khal/utils.py b/khal/utils.py index 694da5bdd..6b8e048a7 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -197,10 +197,10 @@ def fmt(rows): if "calendar-color" in row: row["calendar-color"] = get_color(row["calendar-color"]) - if 'alarms-list' in row and isinstance(row['alarms-list'], list): - row['alarms-list'] = ", ".join( - alarm['description']+"@"+alarm['delta-formatted'] - for alarm in row['alarms-list'] + if "alarms-list" in row and isinstance(row["alarms-list"], list): + row["alarms-list"] = ", ".join( + alarm["description"] + "@" + alarm["delta-formatted"] + for alarm in row["alarms-list"] ) s = format_string.format(**row) @@ -251,8 +251,7 @@ def fmt(rows): "end-necessary-long", "repeat-symbol", "repeat-pattern", - "alarms-list" - "title", + "alarms-listtitle", "organizer", "description", "location", diff --git a/tests/cli_test.py b/tests/cli_test.py index 9f235bc38..334c0992f 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -529,23 +529,19 @@ def test_list_json(runner): def test_list_alarms(runner): runner = runner(days=2) - now = dt.datetime.now().strftime('%d.%m.%Y') - runner.invoke( - main_khal, - f"new {now} 18:00 myevent --alarms -15m,1h".split()) - args = ['list', '--format', '{alarms-list}', '--day-format', ''] + now = dt.datetime.now().strftime("%d.%m.%Y") + runner.invoke(main_khal, f"new {now} 18:00 myevent --alarms -15m,1h".split()) + args = ["list", "--format", "{alarms-list}", "--day-format", ""] result = runner.invoke(main_khal, args) assert not result.exception - assert result.output.strip() == '@15m, @-1h' + assert result.output.strip() == "@15m, @-1h" def test_list_alarms_json(runner): runner = runner() - now = dt.datetime.now().strftime('%d.%m.%Y') - runner.invoke( - main_khal, - f"new {now} 18:00 myevent --alarms 15m,1h".split()) - args = ['list', '--json', 'alarms-list'] + now = dt.datetime.now().strftime("%d.%m.%Y") + runner.invoke(main_khal, f"new {now} 18:00 myevent --alarms 15m,1h".split()) + args = ["list", "--json", "alarms-list"] result = runner.invoke(main_khal, args) expected = '[{"alarms-list": [\ {"delta": -900.0, "description": "", "delta-formatted": "-15m"},\ diff --git a/tests/event_test.py b/tests/event_test.py index a49f8218d..c33e4ed94 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -598,23 +598,24 @@ def test_event_alarm(): def test_event_alarm_list(): """test the content of `alarms-list` attribute""" - event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS) + event = Event.fromString(_get_text("event_dt_simple"), **EVENT_KWARGS) assert event.alarms == [] - event.update_alarms([(dt.timedelta(minutes=30), 'alarm 1'), - (-dt.timedelta(hours=1, minutes=30), 'alarm 2')]) + event.update_alarms( + [(dt.timedelta(minutes=30), "alarm 1"), (-dt.timedelta(hours=1, minutes=30), "alarm 2")] + ) attributes = event.attributes(dt.date.today()) - assert attributes['alarms-list'] == [ - {'delta': 1800.0, 'description': 'alarm 1', 'delta-formatted': '30m'}, - {'delta': -5400.0, 'description': 'alarm 2', 'delta-formatted': '-1h -30m'} + assert attributes["alarms-list"] == [ + {"delta": 1800.0, "description": "alarm 1", "delta-formatted": "30m"}, + {"delta": -5400.0, "description": "alarm 2", "delta-formatted": "-1h -30m"}, ] def test_event_no_alarms_list(): """test that `alarms-list` is empty for an event with no alarms""" - event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS) + event = Event.fromString(_get_text("event_dt_simple"), **EVENT_KWARGS) assert event.alarms == [] attributes = event.attributes(dt.date.today()) - assert attributes['alarms-list'] == [] + assert attributes["alarms-list"] == [] def test_event_attendees(): From d30c6772e19d562ea26a8f900b63582b4381c6c2 Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Thu, 28 May 2026 23:38:22 +0200 Subject: [PATCH 6/7] Update utils.py --- khal/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/khal/utils.py b/khal/utils.py index 6b8e048a7..46394d6b9 100644 --- a/khal/utils.py +++ b/khal/utils.py @@ -251,7 +251,8 @@ def fmt(rows): "end-necessary-long", "repeat-symbol", "repeat-pattern", - "alarms-listtitle", + "alarms-list", + "title", "organizer", "description", "location", From 41ea4a5218dc0aad2f576e6ec1146d6f9a7290b8 Mon Sep 17 00:00:00 2001 From: Dhruva Sambrani <44899822+DhruvaSambrani@users.noreply.github.com> Date: Sun, 31 May 2026 00:07:01 +0200 Subject: [PATCH 7/7] fix test --- tests/cli_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/cli_test.py b/tests/cli_test.py index 334c0992f..7d6a8441e 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -544,9 +544,11 @@ def test_list_alarms_json(runner): args = ["list", "--json", "alarms-list"] result = runner.invoke(main_khal, args) expected = '[{"alarms-list": [\ - {"delta": -900.0, "description": "", "delta-formatted": "-15m"},\ - {"delta": -3600.0, "description": "", "delta-formatted": "-1h"}\ - ]}]' +{"delta": -900.0, "description": "", "delta-formatted": "-15m"}, \ +{"delta": -3600.0, "description": "", "delta-formatted": "-1h"}\ +]}]' + print(result.output) + print(expected) assert not result.exception assert result.output.startswith(expected)