Skip to content

Theme colors with inline TOML comments render as black text (colors.toml parser doesn't strip trailing comments) #32

Description

@Chimmy89

What happened

Omawrite reads background/foreground/accent/selection/mode from ~/.local/state/omarchy/current/theme/colors.toml (Backend::loadOmarchyTheme() in src/backend.cpp). If a theme writes an inline comment after the color value on the same line — which is valid TOML — the parser doesn't strip it, so the resulting "color" string is garbage, QColor fails to parse it, and the text (or background) silently renders as black.

Repro

Given this line in colors.toml (an entirely normal, spec-compliant way to annotate a hex color):

foreground = "#EDE6D6"        # some description of the color

loadOmarchyTheme()'s line parser does:

QString value = line.mid(equals + 1).trimmed();
if (value.size() >= 2
        && ((value.front() == QLatin1Char('"') && value.back() == QLatin1Char('"'))
            || (value.front() == QLatin1Char('\'') && value.back() == QLatin1Char('\''))))
    value = value.mid(1, value.size() - 2);

(src/backend.cpp around lines 593–602)

value ends up as the literal string:

"#EDE6D6"        # some description of the color

Since the string no longer ends with a " (it ends with the comment text), the quote-stripping branch never triggers, and m_themeForeground is set to that whole garbage string. QColor(m_themeForeground) is then invalid, which renders as black — both for the editor's main text color and, since background is parsed the same way, for the window background too. Only lines with no trailing comment parse correctly.

I hit this because my Omarchy theme's colors.toml documents each color with a short inline comment (a very natural thing to do — TOML explicitly supports comments after a value on the same line), e.g.:

background = "#1A1B17"        # ink, warmed
foreground = "#EDE6D6"        # unbleached cloth
accent     = "#F7F2E7"        # shell-white pigment

Every one of background/foreground/accent came out invalid → rendered black-on-black, to the point of being unreadable without selecting the text to highlight it.

Suggested fix

The parser only handles the case where the comment is on its own line (line.startsWith('#') is checked before the = split). It should also strip a trailing # ... comment from the value portion of a key = value line, ideally comment-aware of quoted strings (so a literal # inside a quoted value, if that's ever a case you support, isn't mistaken for a comment start). A minimal fix: after extracting value, if it starts with a quote character, find the matching closing quote and discard everything after it, rather than assuming the value ends at end-of-line.

Workaround

Moving the comment to its own line above the key (rather than trailing it) avoids the bug entirely, and is what I've done for now. Filing this so it doesn't bite the next person who writes an inline comment in their theme's colors.toml — I couldn't find it mentioned in the existing issues.

Version

omawrite 0.5.0-1 (Arch/Omarchy package)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions