zulip / zulip-terminal

Official Zulip terminal client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gruvbox & zt_light themes don't work with pygments 2.16.x

laomuon opened this issue · comments

Description

When I launch with the option -t gruvbox or -t gruvbox_light, I encountered this error:

Possible theme error: Unrecognised color specification 'bold italic' in foreground ('bold italic').

Im on the main branch of the repo

Logs

Traceback (most recent call last):
  File "/home/muon/zulip-terminal/zulipterminal/cli/run.py", line 559, in main
    Controller(
  File "/home/muon/zulip-terminal/zulipterminal/core.py", line 99, in __init__
    self.loop = urwid.MainLoop(self.view, self.theme, screen=screen)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/muon/zulip-terminal/zl-env/lib/python3.11/site-packages/urwid/main_loop.py", line 118, in __init__
    screen.register_palette(palette)
  File "/home/muon/zulip-terminal/zl-env/lib/python3.11/site-packages/urwid/display_common.py", line 856, in register_palette
    self.register_palette_entry(*item)
  File "/home/muon/zulip-terminal/zl-env/lib/python3.11/site-packages/urwid/display_common.py", line 938, in register_palette_entry
    high_256 = AttrSpec(foreground_high, background_high, 256)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/muon/zulip-terminal/zl-env/lib/python3.11/site-packages/urwid/display_common.py", line 537, in __init__
    self.foreground = fg
    ^^^^^^^^^^^^^^^
  File "/home/muon/zulip-terminal/zl-env/lib/python3.11/site-packages/urwid/display_common.py", line 637, in _set_foreground
    raise AttrSpecError(("Unrecognised color specification %s " +
urwid.display_common.AttrSpecError: Unrecognised color specification 'bold italic' in foreground ('bold italic')

Additional context

It seems that pygment:ges has a property bold italic which I think is not directly supported by urwid. A possible workaround:

--- a/zulipterminal/themes/gruvbox_dark.py
+++ b/zulipterminal/themes/gruvbox_dark.py
@@ -93,6 +93,7 @@ META = {
             'n'   : '#bdae93',             # gruvbox: light4
             'p'   : '#bdae93',             # gruvbox: light4
             'w'   : '#bdae93',             # gruvbox: light4
+            'ges'   : '#bdae93, bold, italics',             # gruvbox: light4
         }
     }
 }
diff --git a/zulipterminal/themes/gruvbox_light.py b/zulipterminal/themes/gruvbox_light.py
index e477a9f..dd2c6e4 100644
--- a/zulipterminal/themes/gruvbox_light.py
+++ b/zulipterminal/themes/gruvbox_light.py
@@ -92,6 +92,7 @@ META = {
             'n'   : '#93A1A1',             # gruvbox: light4
             'p'   : '#93A1A1',             # gruvbox: light4
             'w'   : '#93A1A1',             # gruvbox: light4
+            'ges'   : '#bdae93, bold, italics',             # gruvbox: light4
         }
     }
 }

Im not sure however of the color choice. Any thought?

@laomuon Thanks for the detailed bug report and suggestion!

I'm not in a position to manually debug the code right now, though it was a little surprising since gruvbox - and other themes - have worked for me recently. However, after a little dig it looks like this might be due to pygments/pygments#2444, which was new in 2.16.0. Since we only specify pygments>=2.14.0, I suspect that this may be the underlying cause for you.

A short term fix for main - and yourself - might be to install 2.15.x instead, ie. pygments~=2.15.1 or pygments<2.16.0.

Based on the pygments PR, I suspect this may impact multiple or all of our themes, so to unblock pygments>=2.16 we likely want to improve the translation from pygments to urwid. We could try using bold, italics overrides for that entry or others in each theme - if that works, without specifying a color? - but ideally it would be good to avoid lots of unnecessary patches to themes which might be resolved by a more general fix. It is also possible that our current overrides are only necessary due to an issue like this, but that'd be something that would need digging into further.

Thanks again - any feedback on the above would be great!

@laomuon Following up on this, I can confirm locally:

  • This affects gruvbox_dark, gruvbox_light and zt_light
  • This issue does not occur with pygments 2.15.1, but does on 2.16.x
  • Your suggested fix does work, as does bold, italics

I'd like to get this working ASAP first, so I'm capping pygments via #1433 for now.

@laomuon Thanks again for the report - the workaround should solve this for now. If this doesn't fix it or you have other problems or ideas, please continue to file issues or come to chat in #zulip-terminal on chat.zulip.org :)