Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced

Source of release 0.4.1

0.4.1 / src / language / appearance.luc

## Syntax colors are independent of token discovery and UI layout.
from luce_gpu.gpu import Color

pub class SyntaxTheme:
    pub let keyword_color: Color
    pub let string_color: Color
    pub let comment_color: Color
    pub let number_color: Color
    pub let type_color: Color
    pub let other_color: Color
    ## `# mark:` section headers — a comment, but shown brighter so the fold regions stand out.
    pub let section_color: Color

    pub func init(self, colors: map[str, Color]):
        self.keyword_color = colors["keyword"] else Color(0.55, 0.26, 0.65)
        self.string_color = colors["string"] else Color(0.39, 0.58, 0.28)
        self.comment_color = colors["comment"] else Color(0.19, 0.32, 0.31)
        self.number_color = colors["number"] else Color(0.72, 0.43, 0.19)
        self.type_color = colors["type"] else Color(0.12, 0.54, 0.65)
        self.other_color = colors["other"] else Color(0.57, 0.64, 0.36)
        self.section_color = colors["section"] else Color(0.663, 0.812, 0.788)

    pub func color(self, kind: str) -> Color:
        if kind == "keyword":
            return self.keyword_color
        if kind == "string":
            return self.string_color
        if kind == "comment":
            return self.comment_color
        if kind == "section":
            return self.section_color
        if kind == "number":
            return self.number_color
        if kind == "type":
            return self.type_color
        return self.other_color

    ## A TextMate scope resolves to one of the theme's colors by its leading segments, or to
    ## none — leave the text at the editor's foreground — for base or structural scopes. This
    ## lets any grammar color against the same six-color palette; richer selector matching can
    ## come later without changing callers.
    pub func color_for_scope(self, scope: str) -> Color?:
        if scope.starts_with("comment.section"):
            return self.section_color
        if scope.starts_with("comment"):
            return self.comment_color
        if scope.starts_with("string") or scope.starts_with("constant.character") or scope.starts_with("punctuation.definition.string"):
            return self.string_color
        if scope.starts_with("constant.numeric"):
            return self.number_color
        # Prose markup (Markdown): headings and emphasis stand out; code is string-colored, list
        # bullets numeric, block quotes muted, links typed. Placed before the generic entity/keyword
        # rules so heading text (entity.name.section) reads as a heading rather than a type.
        if scope.starts_with("markup.heading") or scope.starts_with("entity.name.section") or scope.starts_with("punctuation.definition.heading"):
            return self.keyword_color
        if scope.starts_with("markup.bold"):
            return self.keyword_color
        if scope.starts_with("markup.italic"):
            return self.type_color
        if scope.starts_with("markup.raw") or scope.starts_with("markup.inline") or scope.starts_with("markup.fenced_code"):
            return self.string_color
        if scope.starts_with("markup.quote"):
            return self.comment_color
        if scope.starts_with("markup.list") or scope.starts_with("punctuation.definition.list"):
            return self.number_color
        if scope.starts_with("markup.underline") or scope.starts_with("markup.link") or scope.starts_with("constant.other.reference.link"):
            return self.type_color
        if scope.starts_with("markup"):
            return self.other_color
        # Assembly directives (.text, .globl, …) read as structure, distinct from mnemonics.
        if scope.starts_with("keyword.control.directive"):
            return self.type_color
        # Built-in type names (`storage.type`: i64, u8, str, C's int/char, …) take the
        # type color, distinct from keywords. Type-declaring keywords — `function` in
        # JS, `class`/`struct` where a grammar tags them storage.type — stay keyword.
        if scope.starts_with("storage.type.function") or scope.starts_with("storage.type.class") or scope.starts_with("storage.type.struct") or scope.starts_with("storage.type.namespace"):
            return self.keyword_color
        if scope.starts_with("storage.type"):
            return self.type_color
        if scope.starts_with("constant.language") or scope.starts_with("keyword") or scope.starts_with("storage"):
            return self.keyword_color
        if scope.starts_with("constant"):
            return self.number_color
        if scope.starts_with("entity.name.type") or scope.starts_with("entity.name.class") or scope.starts_with("support.type") or scope.starts_with("support.class") or scope.starts_with("entity.other.inherited-class"):
            return self.type_color
        if scope.starts_with("entity.name.function") or scope.starts_with("support.function") or scope.starts_with("variable") or scope.starts_with("entity.name.tag"):
            return self.other_color
        if scope.starts_with("entity"):
            return self.type_color
        return none