Skip to content

Instantly share code, notes, and snippets.

@mxcl
Last active March 30, 2019 23:14
Show Gist options
  • Save mxcl/8912454832d426b23025f9223f85127d to your computer and use it in GitHub Desktop.
Save mxcl/8912454832d426b23025f9223f85127d to your computer and use it in GitHub Desktop.
#!/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