Skip to content

opencode: fix theme polarity for light base16 schemes#2322

Closed
losnappas wants to merge 1 commit into
nix-community:masterfrom
losnappas:push-lqlyknxxkyys
Closed

opencode: fix theme polarity for light base16 schemes#2322
losnappas wants to merge 1 commit into
nix-community:masterfrom
losnappas:push-lqlyknxxkyys

Conversation

@losnappas
Copy link
Copy Markdown
Contributor

From #2192 , which seems stalled to me:

OpenCode themes have separate "dark" and "light" color variants,
selected at runtime based on terminal background detection (OSC 11).
The existing mapping always assigns base00 to the "dark" variant and
base06 to "light".
For dark-polarity schemes (base00 = dark background), this is correct.
For light-polarity schemes (e.g. base00 = #ffffff), the assignments are
inverted: when the terminal correctly reports light mode, OpenCode uses
the "light" variant which contains the dark colors, and vice versa.
The result is that light scheme users always see wrong colors regardless
of terminal detection.
Fix this by adding the polarity argument and using builtins.mapAttrs to
swap dark/light values across all theme keys when polarity is "light".
This is simpler than calling a helper per key — the single mapAttrs
transformation flips every {dark, light} pair in one operation.
No behavioral change for dark-polarity schemes (the default code path
is identical).

before:

screenshot-1779636462-18:27:42

after:

screenshot-1779636781-18:33:01

Code logic for dark polarity is unchanged.


@stylix-automation stylix-automation Bot added topic: home-manager Home Manager target topic: modules /modules/ subsystem labels May 24, 2026
@stylix-automation stylix-automation Bot requested a review from arunoruto May 24, 2026 15:43
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #2192 , which seems stalled to me:

This PR seems to have taken the literal code from #2192 without crediting the original #2192 author in the commit.

This also means the

  • I certify that I have the right to submit this contribution under the MIT license

statement is equally doubtful...

OpenCode themes have separate dark and light color variants, selected at runtime based on terminal background detection (OSC 11).

IIUC, if OpenCode follows the terminal polarity, why do we need to override the OpenCode polarity when the terminal should already respect this?

-- #2192 (review)

Could you elaborate on this? Is there no more reliable solution than manually inverting dark and light values, otherwise what is their purpose?

Comment thread modules/opencode/hm.nix Outdated
Comment on lines +219 to +222
tui = {
theme = "stylix";
in
{
tui = { inherit theme; };
themes.${theme} = {
theme = {
accent = {
dark = colors.withHashtag.base0F;
light = colors.withHashtag.base07;
};
background = {
dark = colors.withHashtag.base00;
light = colors.withHashtag.base06;
};
backgroundElement = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base04;
};
backgroundPanel = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
border = {
dark = colors.withHashtag.base02;
light = colors.withHashtag.base03;
};
borderActive = {
dark = colors.withHashtag.base03;
light = colors.withHashtag.base02;
};
borderSubtle = {
dark = colors.withHashtag.base02;
light = colors.withHashtag.base03;
};
diffAdded = {
dark = colors.withHashtag.base0B;
light = colors.withHashtag.base0B;
};
diffAddedBg = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
diffAddedLineNumberBg = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
diffContext = {
dark = colors.withHashtag.base03;
light = colors.withHashtag.base03;
};
diffContextBg = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
diffHighlightAdded = {
dark = colors.withHashtag.base0B;
light = colors.withHashtag.base0B;
};
diffHighlightRemoved = {
dark = colors.withHashtag.base08;
light = colors.withHashtag.base08;
};
diffHunkHeader = {
dark = colors.withHashtag.base03;
light = colors.withHashtag.base03;
};
diffLineNumber = {
dark = colors.withHashtag.base03;
light = colors.withHashtag.base04;
};
diffRemoved = {
dark = colors.withHashtag.base08;
light = colors.withHashtag.base08;
};
diffRemovedBg = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
diffRemovedLineNumberBg = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base05;
};
error = {
dark = colors.withHashtag.base08;
light = colors.withHashtag.base08;
};
info = {
dark = colors.withHashtag.base0C;
light = colors.withHashtag.base0F;
};
markdownBlockQuote = {
dark = colors.withHashtag.base03;
light = colors.withHashtag.base01;
};
markdownCode = {
dark = colors.withHashtag.base0B;
light = colors.withHashtag.base0B;
};
markdownCodeBlock = {
dark = colors.withHashtag.base01;
light = colors.withHashtag.base00;
};
markdownEmph = {
dark = colors.withHashtag.base0A;
light = colors.withHashtag.base09;
};
markdownHeading = {
dark = colors.withHashtag.base0E;
light = colors.withHashtag.base0F;
};
markdownHorizontalRule = {
dark = colors.withHashtag.base04;
light = colors.withHashtag.base03;
};
markdownImage = {
dark = colors.withHashtag.base0D;
light = colors.withHashtag.base0D;
};
markdownImageText = {
dark = colors.withHashtag.base0C;
light = colors.withHashtag.base07;
};
markdownLink = {
dark = colors.withHashtag.base0D;
light = colors.withHashtag.base0D;
};
markdownLinkText = {
dark = colors.withHashtag.base0C;
light = colors.withHashtag.base07;
};
markdownListEnumeration = {
dark = colors.withHashtag.base0C;
light = colors.withHashtag.base07;
};
markdownListItem = {
dark = colors.withHashtag.base0D;
light = colors.withHashtag.base0F;
};
markdownStrong = {
dark = colors.withHashtag.base09;
light = colors.withHashtag.base0A;
};
markdownText = {
dark = colors.withHashtag.base05;
light = colors.withHashtag.base00;
};
primary = {
dark = colors.withHashtag.base0D;
light = colors.withHashtag.base0F;
};
secondary = {
dark = colors.withHashtag.base0E;
light = colors.withHashtag.base0D;
};
success = {
dark = colors.withHashtag.base0B;
light = colors.withHashtag.base0B;
};
syntaxComment = {
dark = colors.withHashtag.base04;
light = colors.withHashtag.base03;
};
syntaxFunction = {
dark = colors.withHashtag.base0D;
light = colors.withHashtag.base0C;
};
syntaxKeyword = {
dark = colors.withHashtag.base0E;

light = colors.withHashtag.base0D;

};
syntaxNumber = {
dark = colors.withHashtag.base09;
light = colors.withHashtag.base0E;
};
syntaxOperator = {
dark = colors.withHashtag.base0C;
light = colors.withHashtag.base0D;
};
syntaxPunctuation = {
dark = colors.withHashtag.base05;
light = colors.withHashtag.base00;
};
syntaxString = {
dark = colors.withHashtag.base0B;
light = colors.withHashtag.base0B;
};
syntaxType = {
dark = colors.withHashtag.base0A;
light = colors.withHashtag.base07;
};
syntaxVariable = {
dark = colors.withHashtag.base07;
light = colors.withHashtag.base07;
};
text = {
dark = colors.withHashtag.base05;
light = colors.withHashtag.base00;
};
textMuted = {
dark = colors.withHashtag.base04;
light = colors.withHashtag.base01;
};
warning = {
dark = colors.withHashtag.base0A;
light = colors.withHashtag.base0A;
};
};
};
};
themes.stylix = { inherit theme; };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert to the previous behavior of parametrizing on the "stylix" theme name.

Comment thread modules/opencode/hm.nix Outdated
Comment on lines +208 to +215
theme =
if polarity == "light" then
builtins.mapAttrs (_: v: {
dark = v.light;
light = v.dark;
}) themeValues
else
themeValues;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider inlining this.

Co-authored-by: Davis Davalos-DeLosh <davis.davalos.delosh@gmail.com>
@losnappas losnappas force-pushed the push-lqlyknxxkyys branch from 23e324c to c67c8d1 Compare June 3, 2026 09:03
@losnappas
Copy link
Copy Markdown
Contributor Author

Thank you for the review 😎 . I added the author of #2192 as co-author, it is their work I just vibe coded on top. As for licensing, well it's now been llm-washed and this is "inspired work."

Could you elaborate on this? Is there no more reliable solution than manually inverting dark and light values, otherwise what is their purpose?

I don't have the slightest idea. Could be just broken on their end, I guess. Devin thinks that should've worked all along. I'll figure it out and get back to ya

@losnappas
Copy link
Copy Markdown
Contributor Author

#2348 better fix, I think.

@losnappas losnappas closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: home-manager Home Manager target topic: modules /modules/ subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants