ChimeHQ/ThemePark
A Swift library for working with syntax highlighting/IDE themes
Installation
dependencies: [
.package(url: "https://github.com/ChimeHQ/ThemePark", branch: "main")
],Usage
Working with themes
TextMate themes:
import ThemePark
let url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try TextMateTheme(with: data)
let urls = TextMateTheme.allXcode Themes:
import ThemePark
let url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try XcodeTheme(with: data)
let urls = XcodeTheme.allBBEdit themes:
import ThemePark
let url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try BBEditTheme(with: data)
let urls = BBEditTheme.allResolving styles
ThemePark's Styling protocol can make use of the SwiftUI environment to adjust for color scheme, contrast, and hover state. You can expose this to your view heirarchy with a modifier:
import SwiftUI
import ThemePark
struct ThemedView: View {
var body: some View {
Text("themed")
.themeSensitive()
}
}Executing queries on a theme:
let styler: any Styling = TextMateTheme.all.randomElement()!
let query = Query(key: .editorBackground, context: .init(colorScheme: .dark))
let style = styler.style(for: query)
print(style.color)
print(style.font)Color schemes
The Variant type captures information about color scheme and contrast. But, do you want the theme to fully customize the UI, or would you like the user's preferences to customize the theme? This is up the the client and the capabilities of the underlying Styling conformance. Many themes also do not support more than one variant, so it can be necessary to query that as well:
let variants = theme.supportedVariantsSyntax element indentification
Most theming systems use strings to provide semantic labels for syntax elements. Eventually, this string->semantic meaning needs to be resolved. Instead of leaving this up to the client/theme designer, ThemePark uses a enum-based system for syntax element indentification. This removes all ambiguity, but can potentially expose mismatches.
This is a very common problem with tree-sitter highlight queries, which have no specification and are often completely ad-hoc.
let specifier = SyntaxSpecifier(highlightsQueryCapture: captureName)Contributing and Collaboration
I would love to hear from you! Issues or pull requests work great. Both a [Matrix space][matrix] and [Discord][discord] are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me on mastodon.
I prefer collaboration, and would love to find ways to work together if you have a similar project.
I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.
By participating in this project you agree to abide by the Contributor Code of Conduct.
[editorconfig]: https://editorconfig.org [build status]: https://github.com/ChimeHQ/ThemePark/actions [build status badge]: https://github.com/ChimeHQ/ThemePark/workflows/CI/badge.svg [platforms]: https://swiftpackageindex.com/ChimeHQ/ThemePark [platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FChimeHQ%2FThemePark%2Fbadge%3Ftype%3Dplatforms [documentation]: https://swiftpackageindex.com/ChimeHQ/ThemePark/main/documentation [documentation badge]: https://img.shields.io/badge/Documentation-DocC-blue [matrix]: https://matrix.to/#/%23chimehq%3Amatrix.org [matrix badge]: https://img.shields.io/matrix/chimehq%3Amatrix.org?label=Matrix [discord]: https://discord.gg/esFpX6sErJ
Package Metadata
Repository: ChimeHQ/ThemePark
Stars: 35
Forks: 2
Open issues: 0
Default branch: main
Primary language: swift
License: BSD-3-Clause
Topics: swift, syntax-highlighting, theme
README: README.md