Repository: pimutils/khal

Issue:
`ikhal` not respecting `{calendar}` in `agenda_event_format`
First of all: Thank you for making and maintaining `khal`. I use it everyday!

According to [the docs](https://lostpackets.de/khal/configure.html#the-view-section), setting

```
agenda_event_format = {calendar-color}{cancelled}{start-end-time-style} ({calendar}) {title} [{location}]{repeat-symbol}{reset}
```

should be respected by both `khal list` and `ikhal`. However, in `ikal`, I only get output such as this:

```
<calendary stuff>    Today (2022-04-08)
…                    8:00-15:00 () Open issue for ikhal [living room]
</calendary stuff>
```

Note the empty parentheses in the “Open issue for ikhal” event. I would've expected to have the name of the calendar there since `agenda_event_format` specifies `({calendar})` (which *does* work as expected in `khal list`).


Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c03753d..843d9cf 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -13,6 +13,7 @@ may want to subscribe to `GitHub's tag feed
 not released
 
 * FIX support for tzlocal >= 4.0
+* FIX ability to show event's calendar in ikhal
 * NEW Add widget to interactive event editor that allows adding attendees as
   comma separated list of email addresses
 * NEW Add support for Python 3.10
diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py
index c6fc795..1801aab 100644
--- a/khal/khalendar/event.py
+++ b/khal/khalendar/event.py
@@ -698,6 +698,7 @@ class Event:
             attributes["calendar"] = cal.get("displayname", self.calendar)
         else:
             attributes["calendar-color"] = attributes["calendar"] = ''
+            attributes["calendar"] = self.calendar
 
         if colors:
             attributes['reset'] = style('', reset=True)


Test patch:
diff --git a/tests/event_test.py b/tests/event_test.py
index 6b52d8a..e3014dd 100644
--- a/tests/event_test.py
+++ b/tests/event_test.py
@@ -16,6 +16,8 @@ EVENT_KWARGS = {'calendar': 'foobar', 'locale': LOCALE_BERLIN}
 LIST_FORMAT = '{calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}'
 SEARCH_FORMAT = '{calendar-color}{cancelled}{start-long}{to-style}' + \
     '{end-necessary-long} {title}{repeat-symbol}'
+FORMAT_CALENDAR = ('{calendar-color}{cancelled}{start-end-time-style} ({calendar}) '
+                   '{title} [{location}]{repeat-symbol}')
 
 
 def test_no_initialization():
@@ -47,6 +49,19 @@ def test_raw_dt():
     assert event.organizer == ''
 
 
+def test_calendar_in_format():
+    """test if the calendar is included in event.format() if specified in the FORMAT
+
+    see #1121
+    """
+    event_dt = _get_text('event_dt_simple')
+    start = BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
+    end = BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))
+    event = Event.fromString(event_dt, start=start, end=end, **EVENT_KWARGS)
+    assert event.format(FORMAT_CALENDAR, dt.date(2014, 4, 9)) == \
+        '09:30-10:30 (foobar) An Event []\x1b[0m'
+
+
 def test_update_simple():
     event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS)
     event_updated = Event.fromString(_get_text('event_dt_simple_updated'), **EVENT_KWARGS)