pimutils / khal

:calendar: CLI calendar application
https://lostpackets.de/khal/
MIT License
2.54k stars 197 forks source link

`auto` Color Erroring for Google Calendars #1335

Closed JBlocklove closed 4 months ago

JBlocklove commented 4 months ago

Describe the bug When using color=auto for a calendar and running khal interactive, Google calendars cause an error to be thrown. This seems to be because they store their color as RGBA, not just RGB and khal doesn't seem to understand the extra characters.

Stack Trace

Traceback (most recent call last):
  File "/home/jason/.local/bin/khal", line 8, in <module>
    sys.exit(main_khal())
             ^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/khal/cli.py", line 505, in interactive
    controllers.interactive(
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/khal/controllers.py", line 633, in interactive
    ui.start_pane(
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/khal/ui/__init__.py", line 1433, in start_pane
    loop = urwid.MainLoop(
           ^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/urwid/event_loop/main_loop.py", line 135, in __init__
    screen.register_palette(palette)
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/urwid/display/common.py", line 1101, in register_palette
    self.register_palette_entry(*item)
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/urwid/display/common.py", line 1189, in register_palette_entry
    high_256 = AttrSpec(foreground_high, background_high, 256)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/urwid/display/common.py", line 598, in __init__
    self.__set_foreground(fg)
  File "/home/jason/.local/share/pipx/venvs/khal/lib/python3.11/site-packages/urwid/display/common.py", line 783, in __set_foreground
    raise AttrSpecError(f"Unrecognised color specification {part!r} in foreground ({foreground!r})")
urwid.display.common.AttrSpecError: Unrecognised color specification '#E8096AFF' in foreground ('#E8096AFF')

To Reproduce Add a calendar from Google with it's metadata synced using vdirsyncer metasync, then set color=auto.

Example:

[[Teaching]]
    path=~/.local/share/calendars/google/google_calendar_name/
    color=auto

Expected behavior The calendar should be rendered using the color with the alpha characters ignored. This occurs with no issue if the color file for the calendar is modified to remove the final two characters.

OS, version, khal version and how you installed it:

[locale] timeformat = %H:%M dateformat = %Y-%m-%d longdateformat = %Y-%m-%d datetimeformat = %Y-%m-%d %H:%M longdatetimeformat = %Y-%m-%d %H:%M firstweekday = 6

[default] default_calendar = Teaching highlight_event_days = true enable_mouse = false

[highlight_days] color = ''


 - The versions of your other python packages [e.g. the output of `pip freeze`]: shouldn't be relevant due to pipx, but I can provide if it's determined to be necessary.
geier commented 4 months ago

I believe this should be fixed in master with https://github.com/pimutils/khal/pull/1333

JBlocklove commented 4 months ago

Yep, that seems to resolve it with no problem. Thanks!