Skip to content

Commit 3cca688

Browse files
authored
feat: Gruvbox Dark theme with same colours in exception tracebacks (ipython#15004)
I hope this is allowed; the documentation does say that users are encouraged to contribute themes! #### Gruvbox Dark Theme This theme was available in older versions of IPython, but the exception tracebacks used colours from another theme. This change adds the theme and also uses the colours from it in tracebacks. ![ipython-gruvbox-dark-demo-1](https://github.com/user-attachments/assets/71b4d008-ea00-4359-9c1a-36249052c263) #### Other Information * The colour used to highlight the source of the exception can make the text unreadable, but a solution for the same has been proposed in ipython#14863 (comment). * Although all lines in `docs/source/config/details.rst` are 80 characters or shorter in length, I didn't break the line I changed because that would affect the Git blame for the lines below. * The names of the variables used to store colour codes for the existing themes in `IPython/utils/PyColorize.py` are actually names of the colours; I used the names of the tokens instead just as a matter of semantics. If you'd like that the names of the colours be used, I can make the change.
2 parents 67d466e + 79f1376 commit 3cca688

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

IPython/utils/PyColorize.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,40 @@ def make_arrow(self, width: int):
331331
symbols={"arrow_body": "\u2500", "arrow_head": "\u25b6", "top_line": "\u2500"},
332332
)
333333

334+
GRUVBOX_VAL_EM = "#D79921"
335+
GRUVBOX_V_NAME = "#83A598"
336+
GRUVBOX_FILENAME = "#FBF1C7"
337+
GRUVBOX_EXCEPTION_NAME = "#FB4934"
338+
GRUVBOX_TOPLINE = "#CC241D"
339+
GRUVBOX_BREAKPOINT_ENABLED = "#FB4934"
340+
GRUVBOX_BREAKPOINT_DISABLED = "#CC241D"
341+
GRUVBOX_PROMPT = "#689D6A"
342+
GRUVBOX_PROMPT_NUM = "#8EC07C"
343+
GRUVBOX_OUT_PROMPT = "#B16286"
344+
GRUVBOX_OUT_PROMPT_NUM = "#D3869B"
345+
gruvbox_dark_theme = Theme(
346+
"gruvbox-dark",
347+
"gruvbox-dark",
348+
{
349+
Token.Lineno: GRUVBOX_PROMPT_NUM,
350+
Token.LinenoEm: f"{GRUVBOX_PROMPT_NUM} bold",
351+
Token.ValEm: f"{GRUVBOX_VAL_EM} bold",
352+
Token.VName: GRUVBOX_V_NAME,
353+
Token.Caret: "",
354+
Token.Filename: GRUVBOX_FILENAME,
355+
Token.FilenameEm: f"{GRUVBOX_FILENAME} bold",
356+
Token.ExcName: f"{GRUVBOX_EXCEPTION_NAME} bold",
357+
Token.Topline: GRUVBOX_TOPLINE,
358+
Token.Breakpoint.Enabled: GRUVBOX_BREAKPOINT_ENABLED,
359+
Token.Breakpoint.Disabled: GRUVBOX_BREAKPOINT_DISABLED,
360+
Token.Prompt: GRUVBOX_PROMPT,
361+
Token.PromptNum: f"{GRUVBOX_PROMPT_NUM} bold",
362+
Token.OutPrompt: GRUVBOX_OUT_PROMPT,
363+
Token.OutPromptNum: f"{GRUVBOX_OUT_PROMPT_NUM} bold",
364+
},
365+
symbols={"arrow_body": "\u2500", "arrow_head": "\u25b6", "top_line": "\u2500"},
366+
)
367+
334368
theme_table: dict[str, Theme] = {
335369
"nocolor": nocolors_theme,
336370
"linux": linux_theme,
@@ -340,6 +374,7 @@ def make_arrow(self, width: int):
340374
"lightbg": lightbg_theme,
341375
"pride": pride_theme,
342376
"pride:l": pridel_theme,
377+
"gruvbox-dark": gruvbox_dark_theme,
343378
}
344379

345380

docs/source/config/details.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ To reflect this, the ``--colors`` flag now is also aliased to ``--theme``.
222222

223223
The default themes included are the same, except lowercase, for ease of typing.
224224

225-
``'nocolor', 'neutral', 'linux', 'lightbg'``, with the addition of ``'pride'``
225+
``'nocolor', 'neutral', 'linux', 'lightbg', 'gruvbox-dark'``, with the addition of ``'pride'``
226226
to celebrate the inclusively of this project (I welcome update to the pride
227227
theme as I'm not a designer myself).
228228

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Gruvbox Dark Theme
2+
==================
3+
4+
Gruvbox Dark is now available as a terminal syntax theme for IPython.

0 commit comments

Comments
 (0)