Skip to content

Commit

Permalink
support for status-symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Jun 15, 2023
1 parent b8a987a commit 243b862
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Package maintainers and users who have to manually update their installation
may want to subscribe to `GitHub's tag feed
<https://github.com/geier/khal/tags.atom>`_.

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
======
Expand Down
3 changes: 3 additions & 0 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 22 additions & 2 deletions khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions tests/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 243b862

Please sign in to comment.