Skip to content

Commit a274224

Browse files
committed
Migrate project infrastructure
1 parent 15ad91c commit a274224

File tree

8 files changed

+1544
-2
lines changed

8 files changed

+1544
-2
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
.DS_Store
2+
13
# Xcode
24
#
35
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
46

57
## Build generated
6-
build/
7-
DerivedData/
8+
/.build
9+
/Packages
10+
/*.xcodeproj
11+
/build
812

913
## Various settings
1014
*.pbxuser

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
env:
2+
global:
3+
- LC_CTYPE=en_US.UTF-8
4+
matrix:
5+
include:
6+
- os: osx
7+
language: objective-c
8+
osx_image: xcode8.2
9+
script:
10+
- swift test
11+
- os: linux
12+
language: generic
13+
sudo: required
14+
dist: trusty
15+
env:
16+
before_install:
17+
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
18+
- wget https://swift.org/builds/swift-3.0.2-release/ubuntu1404/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu14.04.tar.gz
19+
- tar xzf swift-3.0.2-RELEASE-ubuntu14.04.tar.gz
20+
- export PATH=${PWD}/swift-3.0.2-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
21+
script:
22+
- swift test
23+
notifications:
24+
slack:
25+
secure: ek/+U+e44bqP8+QCHojy2LhrN9iwY3N/TNNqNG5FZrp09Vidrd5KXWJOXFxlGrpeWdgTpi089YbEdTfxpcDIudUqDqLwPzS7wePiG2cEC1OT6l3yrhI4AvOe7EsNSOX8gzkuEnmrZVHwLLGe7JeR7JIQKoHMZsBcPYDnO8kRP0Ei3zOh47YUn75SE87egAgZOVBDbZYO3GWRa4WX64s8gaQYQ9a7EoUY0oX9rQ48FJs3rmEIhvIXdcOj9bGX7+o0j7l+IFial/Qh+B6bp4XkZU/tUVP6cuNVI1vxE1weVGCBhgt5wLhXTMewzoE5D1IgMZHVuzIBcDbBthSzQRttLSlYar6xTjXtRtOnb8tqZMWfUj3HBYCFYqtz7PGnZ3IflEVsPJW6tgSsoeB6egjzb8APP9mvhm8+zb1jQG1dqXLWErMjWqhlyPVPmHrxU2w/OLWLAJPY94GVmLnSuOw2pSz41spuEY80JcVVzoRbAOQWrwAujq2S3k93yvKpGq4eaT72Mt8g1CyZesByvzcLk99LEJSpqOIxUqXBd4RwHhay/sq8LllyyqY8ORsxEgwQluOAjEhATO/t/HUsu2ndn1k38U1c4HqXW7FDs1hffYEzZ/PGxciCS6Vt1bfST+iq34pzqpanENQCnX6mSR+D+M7mHlCWdsUihmxEcs5knuM=

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import PackageDescription
2+
3+
let package = Package(name: "FileCheck")

Sources/FileCheck/ANSIColor.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Foundation
2+
3+
/// Represents the possible ANSI color codes.
4+
enum ANSIColor: String {
5+
case black = "\u{001B}[30m"
6+
case red = "\u{001B}[31m"
7+
case green = "\u{001B}[32m"
8+
case yellow = "\u{001B}[33m"
9+
case blue = "\u{001B}[34m"
10+
case magenta = "\u{001B}[35m"
11+
case cyan = "\u{001B}[36m"
12+
case white = "\u{001B}[37m"
13+
case bold = "\u{001B}[1m"
14+
case reset = "\u{001B}[0m"
15+
16+
func name() -> String {
17+
switch self {
18+
case .black: return "Black"
19+
case .red: return "Red"
20+
case .green: return "Green"
21+
case .yellow: return "Yellow"
22+
case .blue: return "Blue"
23+
case .magenta: return "Magenta"
24+
case .cyan: return "Cyan"
25+
case .white: return "White"
26+
case .bold: return "Bold"
27+
case .reset: return "Reset"
28+
}
29+
}
30+
31+
static func all() -> [ANSIColor] {
32+
return [.black, .red, .green,
33+
.yellow, .blue, .magenta,
34+
.cyan, .white, .bold, .reset]
35+
}
36+
}
37+
38+
func + (left: ANSIColor, right: String) -> String {
39+
return left.rawValue + right
40+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import Foundation
2+
3+
/// Represents a stream that can write text with a specific set of ANSI colors
4+
protocol ColoredStream: TextOutputStream {
5+
mutating func write(_ string: String, with: [ANSIColor])
6+
}
7+
8+
extension ColoredStream {
9+
/// Default conformance to TextOutputStream
10+
mutating func write(_ string: String) {
11+
write(string, with: [])
12+
}
13+
}
14+
15+
/// An output stream that prints to an underlying stream including ANSI color
16+
/// codes.
17+
class ColoredANSIStream<StreamTy: TextOutputStream>: ColoredStream {
18+
19+
typealias StreamType = StreamTy
20+
21+
var currentColors = [ANSIColor]()
22+
var stream: StreamType
23+
let colored: Bool
24+
25+
/// Creates a new ColoredANSIStream that prints to an underlying stream.
26+
///
27+
/// - Parameters:
28+
/// - stream: The underlying stream
29+
/// - colored: Whether to provide any colors or to pass text through
30+
/// unmodified. Set this to false and ColoredANSIStream is
31+
/// a transparent wrapper.
32+
init(_ stream: inout StreamType, colored: Bool = true) {
33+
self.stream = stream
34+
self.colored = colored
35+
}
36+
37+
/// Initializes with a stream, always colored.
38+
///
39+
/// - Parameter stream: The underlying stream receiving writes.
40+
required init(_ stream: inout StreamType) {
41+
self.stream = stream
42+
self.colored = true
43+
}
44+
45+
/// Adds a color to the in-progress colors.
46+
func addColor(_ color: ANSIColor) {
47+
guard colored else { return }
48+
stream.write(color.rawValue)
49+
currentColors.append(color)
50+
}
51+
52+
/// Resets this stream back to the default color.
53+
func reset() {
54+
if currentColors.isEmpty { return }
55+
stream.write(ANSIColor.reset.rawValue)
56+
currentColors = []
57+
}
58+
59+
/// Sets the current ANSI color codes to the passed-in colors.
60+
func setColors(_ colors: [ANSIColor]) {
61+
guard colored else { return }
62+
reset()
63+
for color in colors {
64+
stream.write(color.rawValue)
65+
}
66+
currentColors = colors
67+
}
68+
69+
/// Writes the string to the output with the provided colors.
70+
///
71+
/// - Parameters:
72+
/// - string: The string to write
73+
/// - colors: The colors used on the string
74+
func write(_ string: String, with colors: [ANSIColor]) {
75+
self.setColors(colors)
76+
stream.write(string)
77+
self.reset()
78+
}
79+
}

0 commit comments

Comments
 (0)