Terminal Colors for Swift

Related tags

Image Colors
Overview

colors

Language Issues License Build CocoaPods

Terminal string styling for Swift

Colors is a clean and focused solution for string styling in Swift.

Usage

import Colors

print(Colors.blue("Blue string"))
print(Colors.Blue("Bright blue string"))

Addtionaly, you can compose modifiers:

print(Colors.blue(Colors.bgRed("Blue string with red background")))

Or define compositions for convenince:

infix operator >>> { associativity left }
func >>> <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
  return { x in f(g(x)) }
}

var error = Colors.bold >>> Colors.red >>> Colors.underline
print(error("There was an error"))

Installation

CocoaPods

Install cocoapods:

sudo gem install cocoapods

Then specify Colors in your Podfile:

pod 'Colors', '~> 0.1'

Finally run:

pod install

Styles

Bright/Normal Text Colors

  • Black/black
  • Red/red
  • Green/green
  • Yellow/yellow
  • Blue/blue
  • Magenta/magenta
  • Cyan/cyan
  • White/white

Bright/Normal Background Colors

  • BgBlack/bgBlack
  • BgRed/bgRed
  • BgGreen/bgGreen
  • BgYellow/bgYellow
  • BgBlue/bgBlue
  • BgMagenta/bgMagenta
  • BgCyan/bgCyan
  • BgWhite/bgWhite

Text modifiers

  • blink
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

##API

Colors.<style>(text: String) -> String

Applies the specified <style> to the given text. For a list of styles check the styles section above.

Colors.underline("Underlined text")

Colors.colorText(text: String, color: Int) -> String

Requires 8-bit color support from the console.

Colors the letters of the given text with the specified color. color must be an integer from 0-255 representing an 8-bit color. For a list of 8-bit colors check here.

Generally useful if you want to color the text with very specific colors.

for i in 0...255 {
    print(Colors.colorText("a", color: i), terminator: "")
}

Outputs:

Colors.colorBg(text: String, color: Int) -> String

Requires 8-bit color support from the console.

Colors the background of the given text with the specified color. color must be an integer from 0-255 representing an 8-bit color. For a list of 8-bit colors check here.

Generally useful if you want to color the background with very specific colors.

for i in 0...255 {
    print(Colors.colorBg(" ", color: i), terminator: "")
}

Outputs:

Colors.getTextColorer(color: Int) -> (String -> String)

Requires 8-bit color support from the console.

Returns a colorer function that will color the characters of the input string with the specified color.

Useful for defining your own style compositions with 8-bit colors.

infix operator >>> { associativity left }
func >>> <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
  return { x in f(g(x)) }
}

let warning = Colors.getTextColorer(23) >>> Colors.underline >>> Colors.BgRed
print(error("Some Warning"))

Colors.getBgColorer(color: Int) -> (String -> String)

Requires 8-bit color support from the console.

Returns a colorer function that will color the background of the input string with the specified color.

Useful for defining your own style compositions with 8-bit colors.

infix operator >>> { associativity left }
func >>> <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
  return { x in f(g(x)) }
}

let info = Colors.getBgColorer(23) >>> Colors.underline >>> Colors.Red
print(info("Some Warning"))

License

MIT © Paulo Tanaka

You might also like...
BlockiesSwift - Unique blocky identicons generator for Swift
BlockiesSwift - Unique blocky identicons generator for Swift

⚗️ BlockiesSwift This library is a Swift implementation of the Ethereum fork of Blockies which is intended to be used in iOS, watchOS, tvOS and macOS

FacebookImagePicker is Facebook album photo picker written in Swift.
FacebookImagePicker is Facebook album photo picker written in Swift.

Features • Installation • Usage • Translation • License GBHFacebookImagePicker is Facebook's album photo picker written in Swift, built to provide a s

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.

GPUImage 2 Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected] Overview GPUImage 2 is the second generation of th

GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.
GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.

GPUImage 3 Janie Clayton http://redqueengraphics.com @RedQueenCoder Brad Larson http://www.sunsetlakesoftware.com @bradlarson contact@sunsetlakesoftwa

A lightweight generic cache for iOS written in Swift with extra love for images.
A lightweight generic cache for iOS written in Swift with extra love for images.

Haneke is a lightweight generic cache for iOS and tvOS written in Swift 4. It's designed to be super-simple to use. Here's how you would initalize a J

A lightweight and fast image loader for iOS written in Swift.

ImageLoader ImageLoader is an instrument for asynchronous image loading written in Swift. It is a lightweight and fast image loader for iOS. Features

A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.
A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.

ImageScout ImageScout is a Swift implementation of fastimage. It allows you to find the size and type of a remote image by downloading as little as po

A Swift client library for generating URLs with imgix

imgix-swift is a client library for generating image URLs with imgix. Written in Swift, but can be used with Objective-C codebases as well. Installati

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

Comments
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    opened by ReadmeCritic 2
Releases(0.1)
Owner
Paulo Tanaka
Paulo Tanaka
Fetches the most dominant and prominent colors from an image.

UIImageColors iTunes style color fetcher for UIImage and NSImage. It fetches the most dominant and prominent colors. Installation Manual Copy UIImageC

null 3.2k Jan 1, 2023
Create complementary gradients generated from dominant and prominent colors in supplied image. Inspired by Grade.js

ComplimentaryGradientView Create complementary gradients generated from dominant and prominent colors in supplied image. Inspired by Grade.js ❤️ .all

George Kye 728 Dec 17, 2022
Read colors from Xcode assets file.

XcodePalette Read colors from Xcode assets file. How to Use Download the XcodePalette.Executable.zip of the latest release. Extract the XcodePalette U

iMoeNya 0 Nov 12, 2021
The repository for a command line / build pipeline tool for generating colors from a human-readable text file that designers can also use.

ColorPaletteGenerator ColorPaletteGenerator is a tool that takes a human-readable input file describing a color palette, and generates the associated

horseshoe7 0 Dec 7, 2021
ColorKit makes it easy to find the dominant colors of an image

ColorKit ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

Boris Emorine 570 Jan 5, 2023
An Xcode plugin to improve dealing with colors in your project

Crayons is an Xcode7 plugin with various features that improve working with colors in your projects ##Code palettes (iOS only) You can share palettes

Fabio Ritrovato 477 Sep 23, 2022
API surface for Swift plug-ins using the Swift Plugin Manager

SwiftPlugin The minimal API surface required for the Swift Plugin Manager to create instances from a loaded plugin. Additional documentation and refer

Joakim Hassila 2 Mar 25, 2022
Contentful.swift : Swift Delivery SDK for Contentful

contentful.swift - Swift Delivery SDK for Contentful Swift SDK for the Contentfu

An Tran 1 Jan 6, 2022
Swift Package Manager command plugin for Swift-DocC

Swift-DocC Plugin The Swift-DocC plugin is a Swift Package Manager command plugin that supports building documentation for SwiftPM libraries and execu

Apple 225 Dec 24, 2022
Agrume - 🍋 An iOS image viewer written in Swift with support for multiple images.

Agrume An iOS image viewer written in Swift with support for multiple images. Requirements Swift 5.0 iOS 9.0+ Xcode 10.2+ Installation Use Swift Packa

Jan Gorman 601 Dec 26, 2022