Skip to content

Commit d9bb731

Browse files
authored
Merge pull request #82 from onevcat/feature/strikethrough-tests
Add strikethrough style support
2 parents fd9683b + afa4fb8 commit d9bb731

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Playground/main.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ let entry = Rainbow.Entry(
4040
.init(text: "see you!", color: .bit8(39), styles: [.italic])
4141
]
4242
)
43-
print(Rainbow.generateString(for: entry))
43+
print(Rainbow.generateString(for: entry))
44+
45+
print("")
46+
47+
// Strikethrough examples
48+
print("=== Strikethrough Style Examples ===".bold)
49+
print("This is \("deleted text".strikethrough)")
50+
print("Error: \("Deprecated method".red.strikethrough) - use new API instead")
51+
print("\("Old price: $99.99".strikethrough) \("New price: $79.99".green.bold)")
52+
print("")
53+
print("Combining with other styles:")
54+
print("\("Strikethrough + Bold".strikethrough.bold)")
55+
print("\("Strikethrough + Italic".strikethrough.italic)")
56+
print("\("Strikethrough + Underline".strikethrough.underline)")
57+
print("\("Strikethrough + Red + Bold".red.strikethrough.bold)")
58+
print("")
59+
print("Complex example:")
60+
let todoList = """
61+
TODO List:
62+
\("Setup project".strikethrough.dim)
63+
\("Write tests".strikethrough.dim)
64+
- Implement feature
65+
- Code review
66+
"""
67+
print(todoList)

Sources/String+Rainbow.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ extension String {
394394
public var blink: String { return applyingStyle(.blink) }
395395
/// String with text color and background color swapped.
396396
public var swap: String { return applyingStyle(.swap) }
397+
/// String with strikethrough style.
398+
public var strikethrough: String { return applyingStyle(.strikethrough) }
397399
}
398400

399401
// MARK: - Clear Modes Shorthand

Tests/RainbowTests/ConsoleStringTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class ConsoleStringTests: XCTestCase {
105105
XCTAssertEqual(string.underline, "\u{001B}[4mHello Rainbow\u{001B}[0m")
106106
XCTAssertEqual(string.blink, "\u{001B}[5mHello Rainbow\u{001B}[0m")
107107
XCTAssertEqual(string.swap, "\u{001B}[7mHello Rainbow\u{001B}[0m")
108+
XCTAssertEqual(string.strikethrough, "\u{001B}[9mHello Rainbow\u{001B}[0m")
108109
}
109110

110111
func testStringMultipleModes() {
@@ -115,6 +116,9 @@ class ConsoleStringTests: XCTestCase {
115116
XCTAssertEqual(string.onWhite.dim.blink, "\u{001B}[47;2;5mHello Rainbow\u{001B}[0m")
116117
XCTAssertEqual(string.red.blue.onWhite, "\u{001B}[34;47mHello Rainbow\u{001B}[0m")
117118
XCTAssertEqual(string.red.blue.green.blue.blue, "\u{001B}[34mHello Rainbow\u{001B}[0m")
119+
XCTAssertEqual(string.red.strikethrough, "\u{001B}[31;9mHello Rainbow\u{001B}[0m")
120+
XCTAssertEqual(string.strikethrough.underline, "\u{001B}[9;4mHello Rainbow\u{001B}[0m")
121+
XCTAssertEqual(string.red.onYellow.strikethrough, "\u{001B}[31;43;9mHello Rainbow\u{001B}[0m")
118122
}
119123

120124
func testStringClearMode() {
@@ -128,6 +132,8 @@ class ConsoleStringTests: XCTestCase {
128132
XCTAssertEqual(string.red.clearStyles, "\u{001B}[31mHello Rainbow\u{001B}[0m")
129133
XCTAssertEqual(string.red.bold.clearStyles, "\u{001B}[31mHello Rainbow\u{001B}[0m")
130134
XCTAssertEqual(string.red.bold.clearColor, "\u{001B}[1mHello Rainbow\u{001B}[0m")
135+
XCTAssertEqual(string.strikethrough.clearStyles, "Hello Rainbow")
136+
XCTAssertEqual(string.red.strikethrough.clearStyles, "\u{001B}[31mHello Rainbow\u{001B}[0m")
131137
XCTAssertEqual(string.bold.italic.clearStyles, "Hello Rainbow")
132138
}
133139

0 commit comments

Comments
 (0)