diff --git a/Package.swift b/Package.swift index 8766d0c..f07363d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,14 +1,37 @@ -// swift-tools-version: 5.7 +// swift-tools-version: 5.9 import PackageDescription let package = Package( name: "ThemePark", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + .macCatalyst(.v13), + .visionOS(.v1), + ], products: [ .library(name: "ThemePark", targets: ["ThemePark"]), ], targets: [ .target(name: "ThemePark"), - .testTarget(name: "ThemeParkTests", dependencies: ["ThemePark"]), + .testTarget( + name: "ThemeParkTests", + dependencies: ["ThemePark"], + resources: [.copy("Resources")] + ), ] ) + +let swiftSettings: [SwiftSetting] = [ + .enableExperimentalFeature("StrictConcurrency"), + .enableUpcomingFeature("DisableOutwardActorInference"), +] + +for target in package.targets { + var settings = target.swiftSettings ?? [] + settings.append(contentsOf: swiftSettings) + target.swiftSettings = settings +} diff --git a/README.md b/README.md index ed93c36..a6efa10 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ A Swift library for working with syntax highlighting/IDE themes Pretty much every editor has its own theming system. I'd love a package that could be used to intrepret a bunch of different themes for interoperability. I'm not sure how feasible this would be for all the things a theme can control, but I thought at a minimum it could be handy for syntax highlighting. +Supports: + +- TextMate `.tmTheme` with `UTType.textMateTheme` + > [!WARNING] > This is currently very WIP. @@ -21,6 +25,14 @@ dependencies: [ ], ``` +## Usage + +```swift +import ThemePark + + +``` + ## Contributing and Collaboration I would love to hear from you! Issues, Discussions, or pull requests work great. diff --git a/Sources/ThemePark/TextMateTheme.swift b/Sources/ThemePark/TextMateTheme.swift new file mode 100644 index 0000000..de5fb62 --- /dev/null +++ b/Sources/ThemePark/TextMateTheme.swift @@ -0,0 +1,30 @@ +import Foundation + +#if canImport(UniformTypeIdentifiers) +import UniformTypeIdentifiers + +@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) +extension UTType { + public static let textMateTheme = UTType(importedAs: "com.macromates.textmate.theme", conformingTo: .propertyList) +} +#endif + +public struct TextMateTheme: Codable { + public struct Setting: Codable { + public let name: String? + public let scope: String? + public let settings: [String: String] + } + + public let author: String + public let name: String + public let semanticClass: String + public let uuid: UUID + public let settings: [Setting] + + public init(with data: Data) throws { + let decoder = PropertyListDecoder() + + self = try decoder.decode(Self.self, from: data) + } +} diff --git a/Sources/ThemePark/ThemePark.swift b/Sources/ThemePark/ThemePark.swift deleted file mode 100644 index 08b22b8..0000000 --- a/Sources/ThemePark/ThemePark.swift +++ /dev/null @@ -1,2 +0,0 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book diff --git a/Tests/ThemeParkTests/Resources/Blackboard.tmTheme b/Tests/ThemeParkTests/Resources/Blackboard.tmTheme new file mode 100644 index 0000000..0f134ed --- /dev/null +++ b/Tests/ThemeParkTests/Resources/Blackboard.tmTheme @@ -0,0 +1,359 @@ + + + + + author + Domenico Carbotta + gutterSettings + + divider + #0C1021 + selectionBorder + #0C1021 + + name + Blackboard + semanticClass + theme.dark.blackboard + settings + + + settings + + background + #0C1021 + caret + #FFFFFFA6 + foreground + #F8F8F8 + invisibles + #FFFFFF40 + lineHighlight + #FFFFFF0F + selection + #253B76 + + + + name + Comment + scope + comment + settings + + fontStyle + + foreground + #AEAEAE + + + + name + Constant + scope + constant + settings + + fontStyle + + foreground + #D8FA3C + + + + name + Entity + scope + entity + settings + + fontStyle + + foreground + #FF6400 + + + + name + Keyword + scope + keyword + settings + + fontStyle + + foreground + #FBDE2D + + + + name + Storage + scope + storage + settings + + fontStyle + + foreground + #FBDE2D + + + + name + String + scope + string, meta.verbatim + settings + + fontStyle + + foreground + #61CE3C + + + + name + Support + scope + support + settings + + fontStyle + + foreground + #8DA6CE + + + + name + Variable + scope + variable + settings + + fontStyle + + + + + name + Invalid – Deprecated + scope + invalid.deprecated + settings + + fontStyle + italic + foreground + #AB2A1D + + + + name + Invalid – Illegal + scope + invalid.illegal + settings + + background + #9D1E15 + foreground + #F8F8F8 + + + + name + Superclass + scope + entity.other.inherited-class + settings + + fontStyle + italic + foreground + #FF6400 + + + + name + String interpolation + scope + string constant.other.placeholder + settings + + fontStyle + + foreground + #FF6400 + + + + name + meta.function-call.py + scope + meta.function-call.py + settings + + fontStyle + + foreground + #BECDE6 + + + + name + meta.tag + scope + meta.tag, meta.tag entity + settings + + foreground + #7F90AA + + + + name + entity.name.section + scope + entity.name.section + settings + + fontStyle + + foreground + #FFFFFF + + + + name + OCaml variant + scope + keyword.type.variant + settings + + foreground + #D5E0F3 + + + + name + OCaml operator + scope + source.ocaml keyword.operator.symbol + settings + + foreground + #F8F8F8 + + + + name + OCaml infix operator + scope + source.ocaml keyword.operator.symbol.infix + settings + + fontStyle + + foreground + #8DA6CE + + + + name + OCaml prefix operator + scope + source.ocaml keyword.operator.symbol.prefix + settings + + fontStyle + + foreground + #8DA6CE + + + + name + OCaml f-p infix operator + scope + source.ocaml keyword.operator.symbol.infix.floating-point + settings + + fontStyle + underline + + + + name + OCaml f-p prefix operator + scope + source.ocaml keyword.operator.symbol.prefix.floating-point + settings + + fontStyle + underline + + + + name + OCaml f-p constant + scope + source.ocaml constant.numeric.floating-point + settings + + fontStyle + underline + + + + name + LaTeX environment + scope + text.tex.latex meta.function.environment + settings + + background + #FFFFFF08 + + + + name + LaTeX environment (nested) + scope + text.tex.latex meta.function.environment meta.function.environment + settings + + background + #7A96FA08 + + + + name + Latex support + scope + text.tex.latex support.function + settings + + fontStyle + + foreground + #FBDE2D + + + + name + PList unquoted string + scope + source.plist string.unquoted, source.plist keyword.operator + settings + + foreground + #FFFFFF + + + + uuid + A2C6BAA7-90D0-4147-BBF5-96B0CD92D109 + + diff --git a/Tests/ThemeParkTests/TextMateThemeTests.swift b/Tests/ThemeParkTests/TextMateThemeTests.swift new file mode 100644 index 0000000..2e3517d --- /dev/null +++ b/Tests/ThemeParkTests/TextMateThemeTests.swift @@ -0,0 +1,20 @@ +import XCTest +import ThemePark + +final class TextMateThemeTests: XCTestCase { + func testBackboardTheme() throws { + let url = try XCTUnwrap(Bundle.module.url(forResource: "Blackboard", withExtension: "tmTheme", subdirectory: "Resources")) + let data = try Data(contentsOf: url, options: []) + let theme = try TextMateTheme(with: data) + + XCTAssertEqual(theme.uuid, UUID(uuidString: "A2C6BAA7-90D0-4147-BBF5-96B0CD92D109")) + XCTAssertEqual(theme.settings.count, 27) + + let setting = theme.settings[0] + + XCTAssertNil(setting.name) + XCTAssertNil(setting.scope) + + XCTAssertEqual(setting.settings["background"], "#0C1021") + } +} diff --git a/Tests/ThemeParkTests/ThemeParkTests.swift b/Tests/ThemeParkTests/ThemeParkTests.swift deleted file mode 100644 index abc6aaa..0000000 --- a/Tests/ThemeParkTests/ThemeParkTests.swift +++ /dev/null @@ -1,12 +0,0 @@ -import XCTest -@testable import ThemePark - -final class ThemeParkTests: XCTestCase { - func testExample() throws { - // XCTest Documenation - // https://developer.apple.com/documentation/xctest - - // Defining Test Cases and Test Methods - // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods - } -}