Skip to content

Commit c28f632

Browse files
committed
Use mxcl/Chalk for terminal coloring
Replace in-house implementation with a relatively simple library.
1 parent af177ee commit c28f632

File tree

3 files changed

+7
-136
lines changed

3 files changed

+7
-136
lines changed

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ let package = Package(
1313
],
1414
dependencies: [
1515
.package(url: "https://github.com/apple/swift-tools-support-core.git", .exact("0.0.1")),
16+
.package(url: "https://github.com/mxcl/Chalk.git", from: "0.1.0"),
1617
],
1718
targets: [
1819
.target(
19-
name: "FileCheck"),
20+
name: "FileCheck",
21+
dependencies: ["Chalk"]),
2022
.target(
2123
name: "filecheck-tool",
2224
dependencies: ["FileCheck", "SwiftToolsSupport"]),

Sources/FileCheck/ColoredStream.swift

Lines changed: 0 additions & 118 deletions
This file was deleted.

Sources/FileCheck/Diagnostics.swift

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import Foundation
2+
import Chalk
23

34
func diagnose(_ kind : DiagnosticKind, at loc : CheckLocation, with message : String, options: FileCheckOptions) {
45
let disableColors = options.contains(.disableColors) || isatty(fileno(stdout)) != 1
56
if disableColors {
67
print("\(kind): \(message)")
78
} else {
8-
diagnosticStream.write("\(kind): ", with: [.bold, kind.color])
9-
diagnosticStream.write("\(message)\n", with: [.bold])
9+
print("\(kind, color: kind.color, style: .bold): \(message, style: .bold)")
1010
}
1111

1212
let msg = loc.message
1313
if !msg.isEmpty {
14-
if disableColors {
15-
print(msg)
16-
} else {
17-
diagnosticStream.write("\(msg)\n")
18-
}
14+
print(msg)
1915
}
2016
}
2117

@@ -24,7 +20,7 @@ enum DiagnosticKind: String {
2420
case warning
2521
case note
2622

27-
var color: ANSIColor {
23+
var color: Color {
2824
switch self {
2925
case .error: return .red
3026
case .warning: return .magenta
@@ -33,15 +29,6 @@ enum DiagnosticKind: String {
3329
}
3430
}
3531

36-
struct StdOutStream: TextOutputStream {
37-
mutating func write(_ string: String) {
38-
print(string, terminator: "")
39-
}
40-
}
41-
42-
var stdoutStream = StdOutStream()
43-
var diagnosticStream = ColoredANSIStream(&stdoutStream)
44-
4532
enum CheckLocation {
4633
case inBuffer(UnsafePointer<CChar>, UnsafeBufferPointer<CChar>)
4734
case string(String)

0 commit comments

Comments
 (0)