Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ChimeHQ/ThemePark
A Swift library for working with syntax highlighting/IDE themes
https://github.com/ChimeHQ/ThemePark
swift syntax-highlighting theme
Last synced: 13 days ago
JSON representation
A Swift library for working with syntax highlighting/IDE themes
- Host: GitHub
- URL: https://github.com/ChimeHQ/ThemePark
- Owner: ChimeHQ
- License: bsd-3-clause
- Created: 2023-05-04T10:22:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-16T15:32:00.000Z (28 days ago)
- Last Synced: 2024-10-18T12:42:28.214Z (26 days ago)
- Topics: swift, syntax-highlighting, theme
- Language: Swift
- Homepage:
- Size: 90.8 KB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Build Status][build status badge]][build status]
[![Platforms][platforms badge]][platforms]
[![Documentation][documentation badge]][documentation]
[![Matrix][matrix badge]][matrix]# ThemePark
A Swift library for working with syntax highlighting/IDE themesThis package aims to solve two problems: reading theme definitions and making those definitions semantically-addressable.
Supports:
- TextMate `.tmTheme` with `UTType.textMateTheme`
- Xcode `.xccolortheme` with `UTType.xcodeColorTheme`
- BBEdit `.bbColorScheme` with `UTType.bbeditColorScheme`
- Loading themes from known installation sources
- Uniform, structed semantic naming of style defintions## Installation
```swift
dependencies: [
.package(url: "https://github.com/ChimeHQ/ThemePark", branch: "main")
],
```## Usage
### Working with themes
TextMate themes:
```swift
import ThemeParklet url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try TextMateTheme(with: data)let urls = TextMateTheme.all
```Xcode Themes:
```swift
import ThemeParklet url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try XcodeTheme(with: data)let urls = XcodeTheme.all
```BBEdit themes:
```swift
import ThemeParklet url = URL(...)
let data = try Data(contentsOf: url, options: [])
let theme = try BBEditTheme(with: data)let urls = BBEditTheme.all
```### Resolving 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:
```swift
import SwiftUI
import ThemeParkstruct ThemedView: View {
var body: some View {
Text("themed")
.themeSensitive()
}
}
```Executing queries on a theme:
```swift
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:
```swift
let variants = theme.supportedVariants
```### Syntax 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.
```swift
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](https://mastodon.social/@mattiem).
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](CODE_OF_CONDUCT.md).
[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