Skip to content

colors.toml values with a trailing comment render the whole window black #12

Description

@MirasMustimov

An inline comment after a colour value in colors.toml makes the window render
entirely black. Inline comments are legal TOML.

Versions: omacalc 0.2.2-1, omawrite 0.5.0-1, Omarchy 4.0.1

Repro

mode = "dark"
background = "#191724"    # base
foreground = "#e0def4"    # text

Apply the theme, launch the app, window is black.

Cause

Backend::loadOmarchyTheme (src/backend.cpp:457) strips quotes only when the
value both starts and ends with one. With a trailing comment it no longer ends
in a quote, so the quotes stay on and the comment comes with them:

background = "#191724"    # base   ->   ["#191724"    # base]

QColor rejects that and Qt paints an invalid colour black. Background and
foreground both go black, so the window does. mode usually has no trailing
comment, so dark mode is still detected correctly, which makes it look like a
rendering bug rather than a parsing one.

No stock theme puts a comment after a value, and loadsCurrentOmarchyTheme
writes a comment-free palette, which is why this hasn't come up.

Fix

QString value = line.mid(equals + 1).trimmed();
if (!value.isEmpty()
        && (value.front() == QLatin1Char('"') || value.front() == QLatin1Char('\''))) {
    const QChar quote = value.front();
    const int close = value.indexOf(quote, 1);
    if (close > 0)
        value = value.mid(1, close - 1);
} else {
    // A comment marker is preceded by whitespace; an unquoted #rrggbb is not.
    for (int i = 1; i < value.size(); ++i) {
        if (value.at(i) == QLatin1Char('#') && value.at(i - 1).isSpace()) {
            value = value.left(i).trimmed();
            break;
        }
    }
}

Truncating at the first # does not work, hex colours start with one.

Built against Backend: fixes the repro, handles single quotes and bare
values, and all 22 stock themes parse identically to before.

The same parser and the same bug are in omawrite (src/backend.cpp:598).

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