Skip to content

Commit 2f5fc69

Browse files
committed
Add init(styles: StyleParameter...) to Color.Wrap.
As of `swift-600��.0.57.3`, the following statement errors: «Extra argument 'style' in call» `Color.Wrap(style: .Bold)` Removing the supposedly "extra" argument 'style' errors: «'().Type' does not have a member named 'Bold'» `Color.Wrap(.Bold)` The true problem appears to be the ambiguity between the two functions of the form `init(foreground:background:style:)`. `init(styles: StyleParameter...)` for `Color.Wrap` creates a non-ambiguous initializer.
1 parent fdd0bd9 commit 2f5fc69

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Source/Color/Wrap.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public struct Wrap: SelectGraphicRenditionWrapType {
7575
self.init(parameters: parameters)
7676
}
7777

78+
public init(styles: StyleParameter...) {
79+
var parameters: [Parameter] = []
80+
81+
for parameter in styles {
82+
parameters.append(parameter)
83+
}
84+
85+
self.init(parameters: parameters)
86+
}
87+
7888
//------------------------------------------------------------------------------
7989
// MARK: - SelectGraphicRenditionWrap
8090
//------------------------------------------------------------------------------

Tests/PrettyColorsTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class PrettyColorsTests: XCTestCase {
4747
Color.Wrap(foreground: nil as UInt8?, style: .Bold)
4848
Color.Wrap(foreground: nil as Color.Named.Color?, style: .Bold)
4949
[StyleParameter.Bold] as Color.Wrap
50+
Color.Wrap(styles: .Bold)
51+
52+
// Multiple
53+
Color.Wrap(styles: .Bold, .Blink)
5054
}
5155

5256
func test_problem_TypeInference() {
@@ -182,6 +186,10 @@ class PrettyColorsTests: XCTestCase {
182186
)
183187
}(red)
184188

189+
XCTAssert(
190+
red + Color.Wrap(styles: .Bold) == Color.Wrap(foreground: .Red, style: .Bold)
191+
)
192+
185193
// Multiple
186194
let _ = { (wrap: Color.Wrap) -> Void in
187195
var formerlyRed = wrap
@@ -199,6 +207,10 @@ class PrettyColorsTests: XCTestCase {
199207
formerlyRed == Color.Wrap(foreground: .Red, style: .Bold, .Italic)
200208
)
201209
}(red)
210+
211+
XCTAssert(
212+
red + Color.Wrap(styles: .Bold, .Italic) == Color.Wrap(foreground: .Red, style: .Bold, .Italic)
213+
)
202214
}
203215

204216
func testMutableAppend() {

0 commit comments

Comments
 (0)