Skip to content

Commit

Permalink
Xcode theme styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Apr 19, 2024
1 parent e698c2d commit 3b670eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/ThemePark/XcodeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,25 @@ extension XcodeTheme {
}
#endif

extension XcodeTheme: Styling {
public func style(for query: Query) -> Style {
switch query {
case .editorBackground:
let colorComponents = sourceTextBackground
.split(separator: " ")
.compactMap({ Float($0) })
.map({ CGFloat($0) })

let color = Color(
red: colorComponents[0],
green: colorComponents[1],
blue: colorComponents[2],
alpha: colorComponents[3]
)

return Style(font: nil, color: color)
default:
return Style(font: nil, color: Color.black)
}
}
}
9 changes: 9 additions & 0 deletions Tests/ThemeParkTests/XcodeThemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ final class XcodeThemeTests: XCTestCase {
print(XcodeTheme.builtIn.keys)
print(XcodeTheme.userInstalled.keys)
}

func testSemanticQueries() throws {
let url = try XCTUnwrap(Bundle.module.url(forResource: "Default (Light)", withExtension: "xccolortheme", subdirectory: "Resources"))
let theme = try XcodeTheme(contentsOf: url)

let color = try XCTUnwrap(Color(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0))

XCTAssertEqual(theme.style(for: .editorBackground), Style(font: nil, color: color))
}
}

0 comments on commit 3b670eb

Please sign in to comment.