Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Further improve support for escape sequences #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Source/SwiftyTextTable/TextTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

typealias Regex = NSRegularExpression

private let strippingPattern = "\\\u{001B}\\[([0-9][0-9]?m|[0-9](;[0-9]*)*m)"
private let strippingPattern = "\\\u{1B}\\[[0-9][0-9]?(;?[0-9]*)*m"

// We can safely force try this regex because the pattern has be tested to work.
// swiftlint:disable:next force_try
Expand Down
11 changes: 11 additions & 0 deletions Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ class SwiftyTextTableTests: XCTestCase {

let c9 = TextTableColumn(header: "\u{001B}[1;31mHello World\u{001B}[0;30m")
XCTAssertEqual(c9.width(), 11)

let c10 = TextTableColumn(header: "\u{1B}[31mHello World\u{1B}[0m")
XCTAssertEqual(c10.width(), 11)

// Test underline
let c11 = TextTableColumn(header: "\u{1B}[31;4mX\u{1B}[0m")
XCTAssertEqual(c11.width(), 1)

// Test bold
let c12 = TextTableColumn(header: "\u{1B}[31;1mX\u{1B}[0m")
XCTAssertEqual(c12.width(), 1)
#endif
}

Expand Down