krz/org-swift

A dependency-free Swift library that renders org-mode to sanitized HTML. html library org-mode swift

Sources/OrgSwiftUI/OrgKeywordStyle.swift

main
org-swift/Sources/OrgSwiftUI/OrgKeywordStyle.swift history · blame · raw

23 lines · 822 bytes

2 symbols in this file
 1import SwiftUI
 2
 3/// Colors for the part of a heading that is status rather than prose: org's `TODO` and
 4/// `DONE` keywords.
 5///
 6/// The defaults are deliberately semantic rather than literal. A package cannot know the
 7/// palette of the app embedding it, and picking concrete hues — green for done, orange for
 8/// todo — puts colors on screen that belong to no design system and match nothing around
 9/// them. Apps pass their own.
10public struct OrgKeywordStyle: Sendable {
11    public var todo: Color
12    public var done: Color
13
14    public init(todo: Color = .secondary, done: Color = .secondary) {
15        self.todo = todo
16        self.done = done
17    }
18
19    /// The keyword's color, or nil for a keyword that is neither.
20    func color(for keyword: String) -> Color {
21        keyword == "DONE" ? done : todo
22    }
23}