Skip to content

Instantly share code, notes, and snippets.

@mxcl mxcl/chalk-demo.swift
Last active Mar 30, 2019

Embed
What would you like to do?
#!/usr/bin/swift sh
import Foundation
import Chalk // @mxcl == 0.3
extension Int {
var fg: UInt8 {
if !(16..<250 ~= self) || 24...36 ~= (self - 16) % 36 {
return 16
} else {
return 255
}
}
var bg: UInt8 {
return UInt8(self)
}
var paddedString: String {
return " \(self)".padding(toLength: 5, withPad: " ", startingAt: 0)
}
var terminator: String {
return (self + 3).isMultiple(of: 6) ? "\n" : ""
}
}
for x in 0...255 {
print("\(x.paddedString, color: x.fg, background: x.bg)", terminator: x.terminator)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.