mordant icon indicating copy to clipboard operation
mordant copied to clipboard

Is there a way to detect the current color theme?

Open joffrey-bion opened this issue 9 months ago • 2 comments

I'm trying to make inline code elements in markdown (the ones surrounded with backticks) look nice in Clikt help.

The default colors in Clikt for this markdown element type are the default blue highlight over a middle gray background, which has a low contrast and doesn't look very nice:

Image Image

I tried to use some white-over-gray colors like this:

styles["markdown.code.span"] = styles["markdown.code.span"] + (TextColors.white on TextColors.rgb("#32373e"))

It looks slightly nicer in dark-themed terminals: Image

But this is quite bad for light themes (the background is too dark, so too eye-catchy): Image

I would like to adjust the colors depending on what the theme of the current terminal is. But I wonder if this is even possible. Is there any way to know what the default foreground/background colors are?

joffrey-bion avatar May 27 '25 13:05 joffrey-bion

Unfortunately, AFAIK apps running inside a terminal don't have access to any information about the theme the terminal uses, so I don't think this is possible.

ajalt avatar May 27 '25 15:05 ajalt

Oh sorry I forgot to answer this, by the way. Thanks for your reply.

So yeah as I mentioned in another issue, I ended up using a simple green a bit like Google Docs for the markdown code spans, without background, and adjusting the shade to maximize the contrast on both light and dark themes:

styles["markdown.code.span"] = TextColors.rgb("#7fa77d")

See comparison in https://youtrack.jetbrains.com/issue/AMPER-4433/Markdown-code-spans-background-is-too-intense-on-light-theme-in-CLI-help

I think we can close this issue because the question is answered.

joffrey-bion avatar Oct 08 '25 10:10 joffrey-bion