From 243b862b70131647187c10c09300f9dffee5330e Mon Sep 17 00:00:00 2001 From: Christian Geier Date: Thu, 15 Jun 2023 23:38:37 +0200 Subject: [PATCH] support for status-symbol --- CHANGELOG.rst | 7 +++++++ doc/source/usage.rst | 3 +++ khal/khalendar/event.py | 24 ++++++++++++++++++++++-- tests/event_test.py | 9 +++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 970695ae5..4b8107175 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,13 @@ Package maintainers and users who have to manually update their installation may want to subscribe to `GitHub's tag feed `_. +0.11.3 +====== +not released yet + +* NEW event format option `status-symbol` which represents the status of an + event with a symbol (e.g. `✓` for confirmed, `✗` for cancelled, `?` for + tentative) 0.11.2 ====== diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 6439f885a..9e5673f18 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -150,6 +150,9 @@ Several options are common to almost all of :program:`khal`'s commands The status of the event (if this event has one), something like `CONFIRMED` or `CANCELLED`. + status-symbol + The status of the event as a symbol, `✓` or `✗` or `?`. + cancelled The string `CANCELLED` (plus one blank) if the event's status is cancelled, otherwise nothing. diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index a653f94f7..87a9da9e6 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -287,7 +287,10 @@ def symbol_strings(self) -> Dict[str, str]: 'range': '\N{Left right arrow}', 'range_end': '\N{Rightwards arrow to bar}', 'range_start': '\N{Rightwards arrow from bar}', - 'right_arrow': '\N{Rightwards arrow}' + 'right_arrow': '\N{Rightwards arrow}', + 'cancelled': '\N{Cross mark}', + 'confirmed': '\N{Heavy check mark}', + 'tentative': '\N{White question mark ornament}', } else: return { @@ -296,7 +299,10 @@ def symbol_strings(self) -> Dict[str, str]: 'range': '<->', 'range_end': '->|', 'range_start': '|->', - 'right_arrow': '->' + 'right_arrow': '->', + 'cancelled': 'X', + 'confirmed': 'V', + 'tentative': '?', } @property @@ -556,6 +562,19 @@ def _alarm_str(self) -> str: alarmstr = '' return alarmstr + @property + def _status_str(self) -> str: + if self.status == 'CANCELLED': + statusstr = ' ' + self.symbol_strings['cancelled'] + elif self.status == 'TENTATIVE': + statusstr = ' ' + self.symbol_strings['tentative'] + elif self.status == 'CONFIRMED': + statusstr = ' ' + self.symbol_strings['confirmed'] + else: + statusstr = '' + return statusstr + + def format(self, format_string: str, relative_to, env=None, colors: bool=True): """ :param colors: determines if colors codes should be printed or not @@ -682,6 +701,7 @@ def format(self, format_string: str, relative_to, env=None, colors: bool=True): attributes["repeat-symbol"] = self._recur_str attributes["repeat-pattern"] = self.recurpattern attributes["alarm-symbol"] = self._alarm_str + attributes["status-symbol"] = self._status_str attributes["title"] = self.summary attributes["organizer"] = self.organizer.strip() attributes["description"] = self.description.strip() diff --git a/tests/event_test.py b/tests/event_test.py index 34e330439..d5452e0c9 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -316,6 +316,15 @@ def test_event_rd(): assert event.recurring is True +def test_status_confirmed(): + event = Event.fromString(_get_text('event_dt_status_confirmed'), **EVENT_KWARGS) + assert event.status == 'CONFIRMED' + FORMAT_CALENDAR = ('{calendar-color}{status-symbol}{start-end-time-style} ({calendar}) ' + '{title} [{location}]{repeat-symbol}') + + assert event.format(FORMAT_CALENDAR, dt.date(2014, 4, 9)) == \ + ' ✔09:30-10:30 (foobar) An Event []\x1b[0m' + def test_event_d_long(): event_d_long = _get_text('event_d_long') event = Event.fromString(event_d_long, **EVENT_KWARGS)