Add search feature to calendar app with / keybinding using khal search
This commit is contained in:
@@ -330,3 +330,44 @@ class KhalClient(CalendarBackend):
|
||||
# khal edit is interactive, so this is limited via CLI
|
||||
logger.warning("update_event not fully implemented for khal CLI")
|
||||
return None
|
||||
|
||||
def search_events(self, query: str) -> List[Event]:
|
||||
"""Search for events matching a query string.
|
||||
|
||||
Args:
|
||||
query: Search string to match against event titles and descriptions
|
||||
|
||||
Returns:
|
||||
List of matching events
|
||||
"""
|
||||
if not query:
|
||||
return []
|
||||
|
||||
# Use khal search with custom format
|
||||
format_str = "{title}|{start-time}|{end-time}|{start}|{end}|{location}|{uid}|{description}|{organizer}|{url}|{categories}|{status}|{repeat-symbol}"
|
||||
args = ["search", "-f", format_str, query]
|
||||
|
||||
result = self._run_khal(args)
|
||||
|
||||
if result.returncode != 0:
|
||||
logger.error(f"khal search failed: {result.stderr}")
|
||||
return []
|
||||
|
||||
events = []
|
||||
for line in result.stdout.strip().split("\n"):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
# Skip day headers
|
||||
if ", " in line and "|" not in line:
|
||||
continue
|
||||
|
||||
event = self._parse_event_line(line)
|
||||
if event:
|
||||
events.append(event)
|
||||
|
||||
# Sort by start time
|
||||
events.sort(key=lambda e: e.start)
|
||||
|
||||
return events
|
||||
|
||||
Reference in New Issue
Block a user