All Projects → mtynior → Colorizeswift

mtynior / Colorizeswift

Licence: mit
Terminal string styling for Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Colorizeswift

Xcode One Dark
Atom One Dark theme for Xcode
Stars: ✭ 273 (+7.91%)
Mutual labels:  xcode, cocoapods, carthage, color
Shari
Shari is the alternative to the library of UIPickerView(drum roll) in Swift. You can select a item using UITableView.
Stars: ✭ 111 (-56.13%)
Mutual labels:  xcode, cocoapods, carthage
Device
Light weight tool for detecting the current device and screen size written in swift.
Stars: ✭ 1,503 (+494.07%)
Mutual labels:  xcode, cocoapods, carthage
Croc
Swift emoji string parsing library
Stars: ✭ 124 (-50.99%)
Mutual labels:  xcode, cocoapods, carthage
Nextgrowingtextview
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.
Stars: ✭ 1,540 (+508.7%)
Mutual labels:  xcode, cocoapods, carthage
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+4131.62%)
Mutual labels:  xcode, cocoapods, carthage
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-52.96%)
Mutual labels:  xcode, cocoapods, carthage
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-72.73%)
Mutual labels:  xcode, cocoapods, carthage
Donut
Donut is a library for arranging views circularly like a donut.
Stars: ✭ 141 (-44.27%)
Mutual labels:  xcode, cocoapods, carthage
Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: ✭ 152 (-39.92%)
Mutual labels:  xcode, cocoapods, color
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-37.55%)
Mutual labels:  xcode, cocoapods, carthage
Pluggableappdelegate
!! No longer supported !! A lightweight service-oriented AppDelegate for iOS, made in Swift.
Stars: ✭ 96 (-62.06%)
Mutual labels:  xcode, cocoapods, carthage
Xmlmapper
A simple way to map XML to Objects written in Swift
Stars: ✭ 90 (-64.43%)
Mutual labels:  xcode, cocoapods, carthage
Alamofire
Elegant HTTP Networking in Swift
Stars: ✭ 36,896 (+14483.4%)
Mutual labels:  xcode, cocoapods, carthage
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+366.4%)
Mutual labels:  xcode, cocoapods, carthage
Microfeatures Example
📦📱 Example of iOS app built using the uFeatures architecture
Stars: ✭ 112 (-55.73%)
Mutual labels:  xcode, cocoapods, carthage
Localize
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.
Stars: ✭ 253 (+0%)
Mutual labels:  xcode, cocoapods, carthage
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (+326.88%)
Mutual labels:  terminal, ansi, color
Luautocompleteview
Highly configurable autocomplete view that is attachable to any UITextField
Stars: ✭ 55 (-78.26%)
Mutual labels:  xcode, cocoapods, carthage
Natrium
A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.
Stars: ✭ 131 (-48.22%)
Mutual labels:  xcode, cocoapods, carthage

ColorizeSwift

Swift License

Terminal string styling for Swift.

Integration

Swift Package Manager (SPM)

You can use The Swift Package Manager to install ColorizeSwift by adding it to your Package.swift file:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
    ],
    dependencies: [
         .package(url: "https://github.com/mtynior/ColorizeSwift.git", from: "1.5.0"),
    ],
    targets: [
        .target(name: "MyLibrary", dependencies: ["ColorizeSwift"]),
        .testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary", "ColorizeSwift"]),
    ]
)

Manually

You can also manually add ColorizeSwift to you project:

  1. Download ColorizeSwift.swift file,
  2. Drag ColorizeSwift.swift into you project's tree.

CocoaPods

From version 1.5 ColorizeSwift does not support CocoaPods!

Please use SPM or add ColorizeSwift.swift file manually to your project. If you use CocoaPods, you can still use version 1.2. At the moment, latest version1.5, only removed support for CocoaPods and has the same functionality as 1.2, but it might change in the future.

You can use CocoaPods to install ColorizeSwift by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
	pod 'ColorizeSwift'
end

Run pods install to intagrate pods with your project.

Example

You can run sample application:

  1. Open Terminal and go to Example folder.
  2. Run ./build.sh script to build sample application.
  3. Run ./example pacman to launch sample.

Available samples:

  1. styles - prints available styles

    Example - Styles

  2. f1 - prints F1 cars

    Example - F1

  3. pacman - prints Pacman

    Example - Pacman

  4. mario - prints mario

    Example - Mario

Usage

print("Normal")
print("Bold".bold())
print("Dim".dim())
print("Italic".italic())
print("Underline".underline())
print("Blink".blink())
print("Reverse".reverse())
print("hidden".hidden())
print("strikethrough".strikethrough())
print("Red".red())
print("On yellow".onYellow())
print("256 foreground".foregroundColor(.orange1))
print("226 background".backgroundColor(.orange1))
print("Awful combination".colorize(.yellow, background: .red))
    
let nested = "with a blue substring".blue().underline()
print("A bold, green line \(nested) that becomes bold and green again".green().bold())

Styles

Modifiers

  • bold()
  • dim()
  • italic() (not widely supported)
  • underline()
  • reverse()
  • hidden()
  • strikethrough() (not widely supported)
  • reset()

Foreground colors

  • black()
  • red()
  • green()
  • yellow()
  • blue()
  • magenta()
  • cyan()
  • lightGray()
  • darkGray()
  • lightRed()
  • lightGreen()
  • lightYellow()
  • lightBlue()
  • lightMagenta()
  • lightCyan()
  • white()

Background colors

  • onBlack()
  • onRed()
  • onGreen()
  • onYellow()
  • onBlue()
  • onMagenta()
  • onCyan()
  • onLightGray()
  • onDarkGray()
  • onLightRed()
  • onLightGreen()
  • onLightYellow()
  • onLightBlue()
  • onLightMagenta()
  • onLightCyan()
  • onWhite()

256-colors

You can also use 256 colors, but keep in mind that not all Terminal clients support them.

  • foregroundColor(color: TerminalColor)
  • backgroundColor(color: TerminalColor)
  • colorize(foreground: TerminalColor, background: TerminalColor)

Available colors

You can access 256 colors using TerminalColor enumeration.

256 Colors

Escape codes

Sometimes you only need the open code for a modifier. You can access them using TerminalStyle enum:

TerminalStyle.bold.open // "\u{001B}[1m"
TerminalStyle.bold.close  // "\u{001B}[22m"

For 256 colors use:

TerminalColor.red.foregroundStyleCode().open //"\u{001B}[38;5;9m"
TerminalColor.red.backgroundStyleCode().open //"\u{001B}[48;5;9m"

Uncolorize

To get string without any colorization use uncolorized() method:

let styledString = "Awful combination".colorize(.yellow, background: .red) // \u{001B}[48;5;9m\u{001B}[38;5;11mAwful combination\u{001B}[0m\u{001B}[48;5;9m\u{001B}[0m
let withoutStyles = styledString.uncolorized() // "Awful combination"

Disabling colorization

Colorization can be disabled globally:

String.isColorizationEnabled = false // Default: true

You can use this to support a command line option (./example --no-color):

String.isColorizationEnabled = !CommandLine.arguments.contains("--no-color")

To disable colorization when program is running in a pipe (./example | wc) or when not writing to stdout (./example > output.txt):

String.isColorizationEnabled = (isatty(fileno(stdout)) == 1)

Credits

License

ColorizeSwift is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].