From 5c0a52c7ad22ec1323579e84bb0160e387b405ee Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 18:08:38 -0700 Subject: [PATCH 01/10] Compiles and passes with Swift 3.0 --- Source/SwiftyTextTable/TextTable.swift | 45 ++++++++++++----------- SwiftyTextTable.xcodeproj/project.pbxproj | 7 +++- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index 08aa9fe..589a8e9 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -22,14 +22,14 @@ public protocol TextTableObject { var tableValues: [CustomStringConvertible] { get } } -extension String: CustomStringConvertible { - public var description: String { - return self - } -} +//extension String: CustomStringConvertible { +// public var description: String { +// return self +// } +//} private extension String { - private func withPadding(count: Int) -> String { + func withPadding(_ count: Int) -> String { let length = characters.count if length < count { return self + @@ -42,7 +42,7 @@ private extension String { let matches = strippingRegex .matches(in: self, options: [], range: NSRange(location: 0, length: self.characters.count)) .map { - NSString(string: self).substring(with: $0.range(at: 1)) + NSString(string: self).substring(with: $0.rangeAt(1)) } return matches.isEmpty ? self : matches.joined(separator: "") } @@ -52,13 +52,13 @@ private extension String { } } -private func fence(strings: [String], separator: String) -> String { +private func fence(_ strings: [String], separator: String) -> String { return separator + strings.joined(separator: separator) + separator } public struct TextTableColumn { public var header: String - private var values: [String] = [] + fileprivate var values: [String] = [] public init(header: String) { self.header = header @@ -70,7 +70,7 @@ public struct TextTableColumn { } public struct TextTable { - private var columns: [TextTableColumn] + fileprivate var columns: [TextTableColumn] public var columnFence = "|" public var rowFence = "-" public var cornerFence = "+" @@ -80,11 +80,11 @@ public struct TextTable { } public init(objects: [T]) { - columns = objects.isEmpty ? [] : objects[0].dynamicType.tableHeaders.map { TextTableColumn(header: $0) } + columns = objects.isEmpty ? [] : type(of: objects[0]).tableHeaders.map { TextTableColumn(header: $0) } objects.forEach { addRow($0.tableValues) } } - public mutating func addRow(values: [CustomStringConvertible]) { + public mutating func addRow(_ values: [CustomStringConvertible]) { let values = values.count >= columns.count ? values : values + [CustomStringConvertible](repeating: "", count: columns.count - values.count) columns = zip(columns, values).map { @@ -108,19 +108,19 @@ public struct TextTable { } #if !swift(>=3) - internal func repeatElement(element: T, count: Int) -> Repeat { - return Repeat(count: count, repeatedValue: element) + internal func repeatElement(_ element: T, count: Int) -> Repeated { + return Repeated(count: count, repeatedValue: element) } - extension SequenceType where Generator.Element == String { - internal func joined(separator separator: String) -> String { - return joinWithSeparator(separator) + extension Sequence where Iterator.Element == String { + internal func joined(separator: String) -> String { + return self.joined(separator: separator) } } extension Array { internal init(repeating repeatedValue: Element, count: Int) { - self.init(count: count, repeatedValue: repeatedValue) + self.init(repeating: repeatedValue, count: count) } } #endif @@ -128,19 +128,20 @@ public struct TextTable { #if !swift(>=3) || os(Linux) extension NSString { internal func substring(with range: NSRange) -> String { - return substringWithRange(range) + return self.substring(with: range) } } extension NSRegularExpression { - internal func matches(in string: String, options: NSMatchingOptions = [], range: NSRange) -> [NSTextCheckingResult] { - return matchesInString(string, options: options, range: range) + // swiftlint:disable:next line_length + internal func matches(in string: String, options: NSRegularExpression.MatchingOptions = [], range: NSRange) -> [NSTextCheckingResult] { + return self.matches(in: string, options: options, range: range) } } extension NSTextCheckingResult { internal func range(at idx: Int) -> NSRange { - return rangeAtIndex(idx) + return rangeAt(idx) } } #endif diff --git a/SwiftyTextTable.xcodeproj/project.pbxproj b/SwiftyTextTable.xcodeproj/project.pbxproj index 5af0584..afa222b 100644 --- a/SwiftyTextTable.xcodeproj/project.pbxproj +++ b/SwiftyTextTable.xcodeproj/project.pbxproj @@ -174,6 +174,7 @@ }; 3B5BDCEF1C63133100592068 = { CreatedOnToolsVersion = 7.1.1; + LastSwiftMigration = 0800; }; }; }; @@ -301,7 +302,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -344,7 +345,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -369,6 +370,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -390,6 +392,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.scotthoyt.SwiftyTextTable; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; From aa2c18cf2e7516e3247852a2b12646ec69b083bb Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 18:09:15 -0700 Subject: [PATCH 02/10] Cleanup --- Source/SwiftyTextTable/TextTable.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index 589a8e9..1136bb1 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -22,12 +22,6 @@ public protocol TextTableObject { var tableValues: [CustomStringConvertible] { get } } -//extension String: CustomStringConvertible { -// public var description: String { -// return self -// } -//} - private extension String { func withPadding(_ count: Int) -> String { let length = characters.count From de7f0ebe22db59aa613166047ea0ced038581262 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 18:17:25 -0700 Subject: [PATCH 03/10] Add explicitly labelled first parameters for functions. --- Source/SwiftyTextTable/TextTable.swift | 16 ++++++++-------- Tests/SwiftyTextTable/SwiftyTextTableTests.swift | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index 1136bb1..bc39f30 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -23,7 +23,7 @@ public protocol TextTableObject { } private extension String { - func withPadding(_ count: Int) -> String { + func withPadding(count: Int) -> String { let length = characters.count if length < count { return self + @@ -46,7 +46,7 @@ private extension String { } } -private func fence(_ strings: [String], separator: String) -> String { +private func fence(strings: [String], separator: String) -> String { return separator + strings.joined(separator: separator) + separator } @@ -64,7 +64,7 @@ public struct TextTableColumn { } public struct TextTable { - fileprivate var columns: [TextTableColumn] + private var columns: [TextTableColumn] public var columnFence = "|" public var rowFence = "-" public var cornerFence = "+" @@ -75,10 +75,10 @@ public struct TextTable { public init(objects: [T]) { columns = objects.isEmpty ? [] : type(of: objects[0]).tableHeaders.map { TextTableColumn(header: $0) } - objects.forEach { addRow($0.tableValues) } + objects.forEach { addRow(values: $0.tableValues) } } - public mutating func addRow(_ values: [CustomStringConvertible]) { + public mutating func addRow(values: [CustomStringConvertible]) { let values = values.count >= columns.count ? values : values + [CustomStringConvertible](repeating: "", count: columns.count - values.count) columns = zip(columns, values).map { @@ -90,12 +90,12 @@ public struct TextTable { } public func render() -> String { - let separator = fence(columns.map({ column in + let separator = fence(strings: columns.map({ column in return repeatElement(rowFence, count: column.width + 2).joined(separator: "") }), separator: cornerFence) - let header = fence(columns.map({ " \($0.header.withPadding($0.width)) " }), separator: columnFence) + let header = fence(strings: columns.map({ " \($0.header.withPadding(count: $0.width)) " }), separator: columnFence) let values = columns.isEmpty ? "" : (0.. Date: Wed, 7 Sep 2016 18:22:17 -0700 Subject: [PATCH 04/10] Remove declarations for swift < 3 --- Source/SwiftyTextTable/TextTable.swift | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index bc39f30..3fbcb74 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -101,25 +101,7 @@ public struct TextTable { } } -#if !swift(>=3) - internal func repeatElement(_ element: T, count: Int) -> Repeated { - return Repeated(count: count, repeatedValue: element) - } - - extension Sequence where Iterator.Element == String { - internal func joined(separator: String) -> String { - return self.joined(separator: separator) - } - } - - extension Array { - internal init(repeating repeatedValue: Element, count: Int) { - self.init(repeating: repeatedValue, count: count) - } - } -#endif - -#if !swift(>=3) || os(Linux) +#if os(Linux) extension NSString { internal func substring(with range: NSRange) -> String { return self.substring(with: range) From 136f97b07b868a13a01d2955768080bdf10ece09 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 18:24:59 -0700 Subject: [PATCH 05/10] Fix error that didn't add testRenderCustom for linux tests. --- Tests/SwiftyTextTable/SwiftyTextTableTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftyTextTable/SwiftyTextTableTests.swift b/Tests/SwiftyTextTable/SwiftyTextTableTests.swift index 1012a13..0e47dfa 100644 --- a/Tests/SwiftyTextTable/SwiftyTextTableTests.swift +++ b/Tests/SwiftyTextTable/SwiftyTextTableTests.swift @@ -121,7 +121,7 @@ class SwiftyTextTableTests: XCTestCase { static var allTests: [(String, SwiftyTextTableTests -> () throws -> Void)] { return [ ("testRenderDefault", testRenderDefault), - ("testRenderDefault", testRenderDefault), + ("testRenderCustom", testRenderCustom), ("testStripping", testStripping), ("testTableObjects", testTableObjects), ] From c76bc571cc51df213a1675492a1b137d5d414154 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 18:56:04 -0700 Subject: [PATCH 06/10] Remove Xcode73 travis job. Use 9/7/16 swift snapshot for SPM and Linux jobs. --- .travis.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1cd5127..e246816 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ matrix: - script: set -o pipefail && xcodebuild -scheme SwiftyTextTable -project SwiftyTextTable.xcodeproj clean build test | xcpretty env: JOB=Xcode os: osx - osx_image: xcode7.3 + osx_image: xcode8 language: objective-c before_install: - ./scripts/upstall-carthage.sh @@ -18,22 +18,15 @@ matrix: before_deploy: - carthage build --no-skip-current - carthage archive $FRAMEWORK_NAME - - script: set -o pipefail && xcodebuild -scheme SwiftyTextTable -project SwiftyTextTable.xcodeproj clean build test | xcpretty - env: JOB=Xcode8 - os: osx - osx_image: xcode8 - language: objective-c - after_success: - - bash <(curl -s https://codecov.io/bash) - script: - TOOLCHAINS=swift swift build - TOOLCHAINS=swift swift test env: JOB=SPM os: osx - osx_image: xcode7.3 + osx_image: xcode8 language: objective-c before_install: - - export SWIFT_SNAPSHOT=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a + - export SWIFT_SNAPSHOT=swift-DEVELOPMENT-SNAPSHOT-2016-09-07-a - curl https://swift.org/builds/development/xcode/$SWIFT_SNAPSHOT/$SWIFT_SNAPSHOT-osx.pkg -o swift.pkg - sudo installer -pkg swift.pkg -target / - script: @@ -47,7 +40,7 @@ matrix: - wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - - cd .. - gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift - - export SWIFT_SNAPSHOT=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a + - export SWIFT_SNAPSHOT=swift-DEVELOPMENT-SNAPSHOT-2016-09-07-a - export SWIFT_URL=https://swift.org/builds/development/ubuntu1404/$SWIFT_SNAPSHOT/$SWIFT_SNAPSHOT-ubuntu14.04.tar.gz - wget $SWIFT_URL - wget $SWIFT_URL.sig From 0cd8012708fa41c6f64cd8aa1a746f49cad586aa Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Wed, 7 Sep 2016 19:12:18 -0700 Subject: [PATCH 07/10] Rename tests folder to SwiftyTextTableTests (say that 5 times fast) for compatibility with SPM expected module naming conventions. --- SwiftyTextTable.xcodeproj/project.pbxproj | 6 +++--- .../Supporting Files/Info.plist | 0 .../SwiftyTextTableTests.swift | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename Tests/{SwiftyTextTable => SwiftyTextTableTests}/Supporting Files/Info.plist (100%) rename Tests/{SwiftyTextTable => SwiftyTextTableTests}/SwiftyTextTableTests.swift (100%) diff --git a/SwiftyTextTable.xcodeproj/project.pbxproj b/SwiftyTextTable.xcodeproj/project.pbxproj index afa222b..7805a2c 100644 --- a/SwiftyTextTable.xcodeproj/project.pbxproj +++ b/SwiftyTextTable.xcodeproj/project.pbxproj @@ -87,7 +87,7 @@ 3B5BDCF51C63133100592068 /* SwiftyTextTableTests.swift */, ); name = SwiftyTextTableTests; - path = Tests/SwiftyTextTable; + path = Tests/SwiftyTextTableTests; sourceTree = ""; }; 3B5BDD031C631E6200592068 /* Supporting Files */ = { @@ -400,7 +400,7 @@ isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = "Tests/SwiftyTextTable/Supporting Files/Info.plist"; + INFOPLIST_FILE = "Tests/SwiftyTextTableTests/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.scotthoyt.SwiftyTextTableTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -411,7 +411,7 @@ isa = XCBuildConfiguration; buildSettings = { COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = "Tests/SwiftyTextTable/Supporting Files/Info.plist"; + INFOPLIST_FILE = "Tests/SwiftyTextTableTests/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.scotthoyt.SwiftyTextTableTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Tests/SwiftyTextTable/Supporting Files/Info.plist b/Tests/SwiftyTextTableTests/Supporting Files/Info.plist similarity index 100% rename from Tests/SwiftyTextTable/Supporting Files/Info.plist rename to Tests/SwiftyTextTableTests/Supporting Files/Info.plist diff --git a/Tests/SwiftyTextTable/SwiftyTextTableTests.swift b/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift similarity index 100% rename from Tests/SwiftyTextTable/SwiftyTextTableTests.swift rename to Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift From 6d42fb4bb24c61f15a1d8de31fcb1dd595e52995 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Thu, 8 Sep 2016 03:28:24 +0000 Subject: [PATCH 08/10] Changes for Linux compatibility --- Source/SwiftyTextTable/TextTable.swift | 39 +++++++++---------- Tests/LinuxMain.swift | 2 +- .../SwiftyTextTableTests.swift | 2 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index 3fbcb74..ea53e97 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -8,6 +8,24 @@ import Foundation +// MARK: Linux Compatibility +#if os(Linux) + typealias NSRegularExpression = RegularExpression + typealias NSTextCheckingResult = TextCheckingResult + + extension NSString { + internal func substring(with range: NSRange) -> String { + return self.substring(with: range) + } + } + + extension NSTextCheckingResult { + internal func rangeAt(_ idx: Int) -> NSRange { + return range(at: idx) + } + } +#endif + // MARK: Console Escape Stripping private let strippingPattern = "(?:\u{001B}\\[(?:[0-9]|;)+m)*(.*?)(?:\u{001B}\\[0m)+" @@ -100,24 +118,3 @@ public struct TextTable { return [separator, header, separator, values, separator].joined(separator: "\n") } } - -#if os(Linux) - extension NSString { - internal func substring(with range: NSRange) -> String { - return self.substring(with: range) - } - } - - extension NSRegularExpression { - // swiftlint:disable:next line_length - internal func matches(in string: String, options: NSRegularExpression.MatchingOptions = [], range: NSRange) -> [NSTextCheckingResult] { - return self.matches(in: string, options: options, range: range) - } - } - - extension NSTextCheckingResult { - internal func range(at idx: Int) -> NSRange { - return rangeAt(idx) - } - } -#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 7f5388b..521f676 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,6 +1,6 @@ import XCTest -@testable import SwiftyTextTableTestSuite +@testable import SwiftyTextTableTests XCTMain([ testCase(SwiftyTextTableTests.allTests), diff --git a/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift b/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift index 0e47dfa..12ce650 100644 --- a/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift +++ b/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift @@ -118,7 +118,7 @@ class SwiftyTextTableTests: XCTestCase { #if os(Linux) extension SwiftyTextTableTests { - static var allTests: [(String, SwiftyTextTableTests -> () throws -> Void)] { + static var allTests: [(String, (SwiftyTextTableTests) -> () throws -> Void)] { return [ ("testRenderDefault", testRenderDefault), ("testRenderCustom", testRenderCustom), From cd8def545c8d9c8e890a48bd71802b52bc3f9165 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Tue, 13 Sep 2016 19:09:53 -0700 Subject: [PATCH 09/10] Remove stripping functionality from Linux. --- Source/SwiftyTextTable/TextTable.swift | 62 +++++++++---------- .../SwiftyTextTableTests.swift | 32 +++++----- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/Source/SwiftyTextTable/TextTable.swift b/Source/SwiftyTextTable/TextTable.swift index ea53e97..5f712a6 100644 --- a/Source/SwiftyTextTable/TextTable.swift +++ b/Source/SwiftyTextTable/TextTable.swift @@ -8,38 +8,34 @@ import Foundation -// MARK: Linux Compatibility +// MARK: Console Escape Stripping +// Because of an error using the Linux implementation of Foundation's RegularExpression, +// escape stripping is only available on Apple platforms #if os(Linux) - typealias NSRegularExpression = RegularExpression - typealias NSTextCheckingResult = TextCheckingResult - - extension NSString { - internal func substring(with range: NSRange) -> String { - return self.substring(with: range) + private extension String { + func stripped() -> String { + return self } } - - extension NSTextCheckingResult { - internal func rangeAt(_ idx: Int) -> NSRange { - return range(at: idx) +#else + private let strippingPattern = "(?:\u{001B}\\[(?:[0-9]|;)+m)*(.*?)(?:\u{001B}\\[0m)+" + + // We can safely force try this regex because the pattern has be tested to work. + // swiftlint:disable:next force_try + private let strippingRegex = try! NSRegularExpression(pattern: strippingPattern, options: []) + + private extension String { + func stripped() -> String { + let matches = strippingRegex + .matches(in: self, options: [], range: NSRange(location: 0, length: self.characters.count)) + .map { + NSString(string: self).substring(with: $0.rangeAt(1)) + } + return matches.isEmpty ? self : matches.joined(separator: "") } } #endif -// MARK: Console Escape Stripping -private let strippingPattern = "(?:\u{001B}\\[(?:[0-9]|;)+m)*(.*?)(?:\u{001B}\\[0m)+" - -// We can safely force try this regex because the pattern has be tested to work. -// swiftlint:disable:next force_try -private let strippingRegex = try! NSRegularExpression(pattern: strippingPattern, options: []) - -// MARK: - TextTable Protocols - -public protocol TextTableObject { - static var tableHeaders: [String] { get } - var tableValues: [CustomStringConvertible] { get } -} - private extension String { func withPadding(count: Int) -> String { let length = characters.count @@ -50,20 +46,18 @@ private extension String { return self } - func stripped() -> String { - let matches = strippingRegex - .matches(in: self, options: [], range: NSRange(location: 0, length: self.characters.count)) - .map { - NSString(string: self).substring(with: $0.rangeAt(1)) - } - return matches.isEmpty ? self : matches.joined(separator: "") - } - func strippedLength() -> Int { return stripped().characters.count } } +// MARK: - TextTable Protocols + +public protocol TextTableObject { + static var tableHeaders: [String] { get } + var tableValues: [CustomStringConvertible] { get } +} + private func fence(strings: [String], separator: String) -> String { return separator + strings.joined(separator: separator) + separator } diff --git a/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift b/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift index 12ce650..1588d46 100644 --- a/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift +++ b/Tests/SwiftyTextTableTests/SwiftyTextTableTests.swift @@ -51,26 +51,30 @@ class SwiftyTextTableTests: XCTestCase { } func testStripping() { - let c1 = TextTableColumn(header: "\u{001B}[0mHello\u{001B}[0m") - XCTAssertEqual(c1.width, 5) + #if os(Linux) + return + #else + let c1 = TextTableColumn(header: "\u{001B}[0mHello\u{001B}[0m") + XCTAssertEqual(c1.width, 5) - let c2 = TextTableColumn(header: "\u{001B}[31m\u{001B}[4;31;93mHello World\u{001B}[0m\u{001B}[0m") - XCTAssertEqual(c2.width, 11) + let c2 = TextTableColumn(header: "\u{001B}[31m\u{001B}[4;31;93mHello World\u{001B}[0m\u{001B}[0m") + XCTAssertEqual(c2.width, 11) - let c3 = TextTableColumn(header: "\u{001B}[0m\u{001B}[0m") - XCTAssertEqual(c3.width, 0) + let c3 = TextTableColumn(header: "\u{001B}[0m\u{001B}[0m") + XCTAssertEqual(c3.width, 0) - let c4 = TextTableColumn(header: "\u{001B}[31mHello World\u{001B}[0m") - XCTAssertEqual(c4.width, 11) + let c4 = TextTableColumn(header: "\u{001B}[31mHello World\u{001B}[0m") + XCTAssertEqual(c4.width, 11) - let c5 = TextTableColumn(header: "\u{001B}[4;31;42;93;5mHello World\u{001B}[0m") - XCTAssertEqual(c5.width, 11) + let c5 = TextTableColumn(header: "\u{001B}[4;31;42;93;5mHello World\u{001B}[0m") + XCTAssertEqual(c5.width, 11) - let c6 = TextTableColumn(header: "\u{001B}[4;31;93mHello World\u{001B}[0m") - XCTAssertEqual(c6.width, 11) + let c6 = TextTableColumn(header: "\u{001B}[4;31;93mHello World\u{001B}[0m") + XCTAssertEqual(c6.width, 11) - let c7 = TextTableColumn(header: "Hello World") - XCTAssertEqual(c7.width, 11) + let c7 = TextTableColumn(header: "Hello World") + XCTAssertEqual(c7.width, 11) + #endif } func testTableObjects() { From a01daba2eac3b3de8a35c91c766ba1c118117e27 Mon Sep 17 00:00:00 2001 From: Scott Hoyt Date: Tue, 13 Sep 2016 19:40:02 -0700 Subject: [PATCH 10/10] Update README and CHANGELOG --- CHANGELOG.md | 21 +++++++++++++++++++-- README.md | 23 +++++++++++------------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66cf9de..c4efaec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,29 @@ ##### Breaking +* `SwiftyTextTable` adopts the new Swift 3.0 convention of explicit first + parameter labels for functions. +* Linux support for dealing with console formatting escape sequences has been + removed for the time being due to regular expression portability problems. + +##### Enhancements + +* Swift 3.0 support! + +##### Bug Fixes + +* None + +## 0.3.1: Swift 2.3 Support + +##### Breaking + * None ##### Enhancements -* SwiftyTextTable is now compatible with both Swift 2.2 and Swift 3.0 on OS X - and Linux thanks to the great work of [Norio Nomura](https://github.com/norio-nomura). +* SwiftyTextTable is now compatible with Swift 2.3 on OS X and Linux thanks to + the great work of [Norio Nomura](https://github.com/norio-nomura). ##### Bug Fixes diff --git a/README.md b/README.md index 6fc0064..23dff03 100644 --- a/README.md +++ b/README.md @@ -7,20 +7,12 @@ A lightweight Swift library for generating text tables. [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) ![Platform OS X + Linux](https://img.shields.io/badge/Platform-OS%20X%20%2B%20Linux-blue.svg) -[![Language Swift 2.3](https://img.shields.io/badge/Language-Swift%202.3-orange.svg)](https://swift.org) +[![Language Swift 3.0](https://img.shields.io/badge/Language-Swift%203.0-orange.svg)](https://swift.org) -## Swift 3.0 +## Swift Language Support -Currently Swift 3.0 support is a work in progress. The library is stable under -OS X using Xcode 8 or SPM, but not Linux. To access Swift 3.0 support use the -branch `swift3`. - -The Swift 3.0 implementation is not backwards compatible with Swift < 3.0 and -introduces breaking changes due to explicit first parameter labels for -functions. - -SwiftyTextTable 0.4.0 will introduce Swift 3.0 support. To prevent problems in -codebases not yet updated to Swift 3.0, pin your version to `0.3.1`. +`SwiftyTextTable` is now Swift 3.0 compatible! The last release to support Swift +2.3 was [0.3.1](https://github.com/scottrhoyt/SwiftyTextTable/releases/tag/0.3.1). ## Installation @@ -142,6 +134,13 @@ print(tableString) */ ``` +#### Console Formatting Support +*Not currently available in Linux.* + +`SwiftyTextTable` will recognize many console escape sequences used to format +output (e.g. [Rainbow](https://github.com/onevcat/Rainbow)) and account for them +in constructing the table. + ### Creating Tables from Arrays of Objects with `TextTableObject` Let's say you have an array of objects that looks this: