Skip to content

Commit

Permalink
Lowercase enum names and static properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhealy committed Sep 9, 2016
1 parent 6d528b9 commit 5534565
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 150 deletions.
6 changes: 3 additions & 3 deletions Source/Color · EightBit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension Color {
public var code: (enable: [UInt8], disable: UInt8?) {
return (
enable: [
(self.level == .Foreground ? 38 : 48),
(self.level == .foreground ? 38 : 48),
5,
self.color
],
Expand All @@ -18,14 +18,14 @@ extension Color {
foreground color: UInt8
) {
self.color = color
self.level = Level.Foreground
self.level = Level.foreground
}

public init(
background color: UInt8
) {
self.color = color
self.level = Level.Background
self.level = Level.background
}

}
Expand Down
40 changes: 20 additions & 20 deletions Source/Color · Named.swift
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
extension Color {
public struct Named: Parameter, ColorType {
public enum Color: UInt8 {
case Black = 30
case Red
case Green
case Yellow
case Blue
case Magenta
case Cyan
case White
case black = 30
case red
case green
case yellow
case blue
case magenta
case cyan
case white
}

public enum Brightness {
case Bright
case NonBright
case bright
case nonBright

public var additive: UInt8 { return self == .Bright ? 60 : 0 }
public var additive: UInt8 { return self == .bright ? 60 : 0 }

public mutating func toggle() {
switch self {
case .Bright: self = .NonBright
case .NonBright: self = .Bright
case .bright: self = .nonBright
case .nonBright: self = .bright
}
}

}

public var color: Color
public var brightness = Brightness.NonBright
public var level = Level.Foreground
public var brightness = Brightness.nonBright
public var level = Level.foreground

public var code: (enable: [UInt8], disable: UInt8?) {
return (
enable: [
self.color.rawValue +
self.brightness.additive +
(self.level == .Foreground ? 0 : 10)
(self.level == .foreground ? 0 : 10)
],
disable: nil
)
}

public init(
foreground color: Color,
brightness: Brightness = .NonBright
brightness: Brightness = .nonBright
) {
self.color = color
self.brightness = brightness
self.level = Level.Foreground
self.level = Level.foreground
}

public init(
background color: Color,
brightness: Brightness = .NonBright
brightness: Brightness = .nonBright
) {
self.color = color
self.brightness = brightness
self.level = Level.Background
self.level = Level.background
}

}
Expand Down
10 changes: 5 additions & 5 deletions Source/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public protocol ColorType: Parameter {

/// Foreground/Background
public enum Level {
case Foreground
case Background
case foreground
case background

public mutating func toggle() {
if self == .Foreground {
self = .Background
if self == .foreground {
self = .background
} else {
self = .Foreground
self = .foreground
}
}

Expand Down
24 changes: 12 additions & 12 deletions Source/ColorWrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ public struct Wrap: SelectGraphicRenditionWrapType {

public var foreground: Parameter? {
get {
return self.filter(level: .Foreground).first
return self.filter(level: .foreground).first
}
mutating set(newForeground) {
self.parameters =
[newForeground].flatMap { $0 } + // Empty array or array containing new foreground
self.filter(level: .Foreground, inverse: true) // All non-foreground parameters
self.filter(level: .foreground, inverse: true) // All non-foreground parameters
}
}

public var background: Parameter? {
get {
return self.filter(level: .Background).first
return self.filter(level: .background).first
}
mutating set(newBackground) {
self.parameters =
[newBackground].flatMap { $0 } + // Empty array or array containing new background
self.filter(level: .Background, inverse: true) // All non-background parameters
self.filter(level: .background, inverse: true) // All non-background parameters
}
}

Expand All @@ -156,14 +156,14 @@ public struct Wrap: SelectGraphicRenditionWrapType {

/// Synchronously transform all ColorTypes with a `Level` of `Foreground`.
public mutating func foreground(transform: (ColorType) -> ColorType) -> Bool {
let transformation = levelTransform(.Foreground, transform: transform)
let transformation = levelTransform(.foreground, transform: transform)
self.parameters = transformation.parameters
return transformation.transformed
}

/// Synchronously transform all ColorTypes with a `Level` of `Background`.
public mutating func background(transform: (ColorType) -> ColorType) -> Bool {
let transformation = levelTransform(.Background, transform: transform)
let transformation = levelTransform(.background, transform: transform)
self.parameters = transformation.parameters
return transformation.transformed
}
Expand Down Expand Up @@ -244,8 +244,8 @@ extension Color.Wrap: ExpressibleByArrayLiteral {}
extension Color.Wrap: Equatable {

public enum EqualityType {
case Array
case Set
case array
case set
}

private func setEqualilty(_ a: Color.Wrap, _ b: Color.Wrap) -> Bool {
Expand All @@ -255,19 +255,19 @@ extension Color.Wrap: Equatable {
return x == y
}

public func isEqual(to other: Color.Wrap, equality: Color.Wrap.EqualityType = .Array) -> Bool {
public func isEqual(to other: Color.Wrap, equality: Color.Wrap.EqualityType = .array) -> Bool {
switch equality {
case .Array:
case .array:
return
self.parameters.count == other.parameters.count &&
self.code.enable == other.code.enable
case .Set:
case .set:
return setEqualilty(self, other)
}
}

}

public func == (a: Color.Wrap, b: Color.Wrap) -> Bool {
return a.isEqual(to: b, equality: .Array)
return a.isEqual(to: b, equality: .array)
}
52 changes: 26 additions & 26 deletions Source/StyleParameter.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/// Based on: ECMA-048 — 8.3.117
public enum StyleParameter: UInt8, Parameter {
// Reference: Terminal Support Table: https://github.com/jdhealy/PrettyColors/wiki/Terminal-Support
case Bold = 01 // bold or increased intensity
case Faint = 02 // faint, decreased intensity or second colour
case Italic = 03 // italicized
case Underlined = 04 // singly underlined
case BlinkSlow = 05 // slowly blinking (less then 150 per minute)
case Blink = 06 // rapidly blinking (150 per minute or more)
case Negative = 07 // negative image — a.k.a. Inverse
case Concealed = 08 // concealed characters
case CrossedOut = 09 // (characters still legible but marked as to be deleted)
case Font1 = 11
case Font2 = 12
case Font3 = 13
case Font4 = 14
case Font5 = 15
case Font6 = 16
case Font7 = 17
case Font8 = 18
case Font9 = 19
case Fraktur = 20 // Gothic
case UnderlinedDouble = 21 // doubly underlined
case Normal = 22 // normal colour or normal intensity (neither bold nor faint)
case Positive = 27 // positive image
case Revealed = 28 // revealed characters
case Framed = 51
case Encircled = 52
case Overlined = 53
case bold = 01 // bold or increased intensity
case faint = 02 // faint, decreased intensity or second colour
case italic = 03 // italicized
case underlined = 04 // singly underlined
case blinkSlow = 05 // slowly blinking (less then 150 per minute)
case blink = 06 // rapidly blinking (150 per minute or more)
case negative = 07 // negative image — a.k.a. Inverse
case concealed = 08 // concealed characters
case crossedOut = 09 // (characters still legible but marked as to be deleted)
case font1 = 11
case font2 = 12
case font3 = 13
case font4 = 14
case font5 = 15
case font6 = 16
case font7 = 17
case font8 = 18
case font9 = 19
case fraktur = 20 // Gothic
case underlinedDouble = 21 // doubly underlined
case normal = 22 // normal colour or normal intensity (neither bold nor faint)
case positive = 27 // positive image
case revealed = 28 // revealed characters
case framed = 51
case encircled = 52
case overlined = 53

public struct Reset {
/// Some parameters have corresponding resets,
Expand Down
28 changes: 14 additions & 14 deletions Tests/Unit/Equality.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ class EqualityTests: XCTestCase {
let one = [
Color.EightBit(foreground: 100),
Color.EightBit(background: 200),
(StyleParameter.Encircled)
(StyleParameter.encircled)
] as Color.Wrap

let two = [
Color.EightBit(background: 200),
StyleParameter.Encircled,
StyleParameter.encircled,
Color.EightBit(foreground: 100)
] as Color.Wrap

XCTAssert(
one.isEqual(to: two, equality: Color.Wrap.EqualityType.Set)
one.isEqual(to: two, equality: Color.Wrap.EqualityType.set)
)
XCTAssert(
!one.isEqual(to: two, equality: Color.Wrap.EqualityType.Array)
!one.isEqual(to: two, equality: Color.Wrap.EqualityType.array)
)

// Defaults to Array Equality
Expand All @@ -44,14 +44,14 @@ class EqualityTests: XCTestCase {

func testB() {
let one = [
Color.Named(foreground: .Green),
Color.Named(foreground: .green),
Color.EightBit(background: 200),
StyleParameter.Encircled
StyleParameter.encircled
] as Color.Wrap

let two = [
Color.EightBit(background: 200),
StyleParameter.Encircled,
StyleParameter.encircled,
Color.EightBit(foreground: 100)
] as Color.Wrap

Expand All @@ -60,35 +60,35 @@ class EqualityTests: XCTestCase {

func testC() {
let one = [
Color.Named(foreground: .Green),
Color.Named(foreground: .green),
Color.EightBit(background: 200),
StyleParameter.Encircled
StyleParameter.encircled
] as Color.Wrap

let two = [
Color.EightBit(background: 200),
StyleParameter.CrossedOut,
StyleParameter.crossedOut,
Color.EightBit(foreground: 100)
] as Color.Wrap

XCTAssert(one != two)
}

func testD() {
let one = Color.Wrap(foreground: .Green)
let one = Color.Wrap(foreground: .green)

let two = [
Color.EightBit(background: 200),
StyleParameter.CrossedOut,
StyleParameter.crossedOut,
Color.EightBit(foreground: 100)
] as Color.Wrap

XCTAssert(one != two)
}

func testE() {
let one: Parameter = Color.Named(foreground: .Yellow)
let two: Parameter = Color.Named(background: .Yellow)
let one: Parameter = Color.Named(foreground: .yellow)
let two: Parameter = Color.Named(background: .yellow)
// TODO: DOCUMENT: Parameters don't conform to Equatable
XCTAssert(!(one == two))
XCTAssert(one != two)
Expand Down
Loading

0 comments on commit 5534565

Please sign in to comment.