Coloring shift

Quick terminal block form.

Consolidation

Swift Package Manager (SPM)

You can use the Swift package manager to install ColorizeSwift by adding it to your Package.fast file:

// Swift-tools-version:4.0
// Swift-tools-version explains the minimum Swift version 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, starting with: 1.5.0),
], targets
: [
.target(name : MyLibrary, targets : [ColorizeSwift]),
.testTarget(name : MyLibraryTests, targets : [MyLibrary, ColorizeSwift]),
] )

Manual

You can also add ColorizeSwift to your project manually:

  1. Download the file ColorizeSwift.fast,
  2. Drag ColorizeSwift.fast into your project tree.

Cocoa beans

As of version 1.5, ColorizeSwift does not support CocoaPods!

Use SPM or manually add the ColorizeSwift.fast file to your project.
If you are using CocoaPods, you can continue to use version 1.2. Currently, the latest version 1.5 only supports CocoaPods and has the same features as 1.2, but this could change in the future.

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

Platform :ios, ‘9.0’
use_frameworks!

goal MyApp create
pod ColorizeSwift
end

Start by installing the capsules to include them in your project.

Example

You can start a sample request:

  1. Open the device and navigate to the samples folder.
  2. Run the ./build.sh script to create a sample application.
  3. Run ./example pacman to start the example.

Available models :

  1. Styles – styles available for printing

  1. f1 – F1 vehicle printer

Terminal string styling for Swift

  1. Pac-Man – Print Pac-Man

Terminal string styling for Swift

  1. mario – mario prints

Terminal string styling for Swift

Use of

print (Normal)
print (bold())
print (Dim.dim())
print (italic())
print (underline.underline())
print (Blink.blink())
print (Reverse.reverse())
print (hidden.hidden())
print (strikeout())
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 the background blue.blue().underline()
print(bold, green (nested) line that becomes bold and green again.green().bold().

Types

Modifiers

  • bold()
  • dark()
  • italic() (not supported by the majority)
  • underline()
  • inverted()
  • hidden()
  • strikethrough() (not widely supported)
  • reset()

Foreground colours

  • black()
  • red()
  • green()
  • yellow()
  • blue()
  • purple()
  • blue()
  • lightGray()
  • darkGray()
  • lightRed()
  • light green()
  • pale yellow()
  • light blue()
  • lightMagenta()
  • lightCyan()
  • white()

Background colors

  • in black()
  • onRed()
  • onGreen()
  • for yellow()
  • onBlue()
  • onMagenta()
  • onCyan()
  • onLightGray()
  • onDarkGray()
  • onLightRed()
  • onLightGreen()
  • onLichtgeel()
  • onLightBlue()
  • onLightMagenta()
  • onLightCyan()
  • opWhite()

256 colours

You can also use 256 colors, but note that not all terminal clients support these colors.

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

Available colours

You can access 256 colors with TerminalColor enumeration.

Terminal string styling for Swift

Escape codes

Sometimes it is enough to have open source code for a modifier. You can access the system using TerminalStyle enumeration:

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

Use 256 colors :

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

Do not paint

Use the uncolored() method to get a string with no coloring:

let styledString = Terrible Combination.colorize(.yellow, background: .red) // u{001B}[48;5;9mu{001B}[38;5;11Terrible Combinationu{001B}[0mu{001B}[48;5;9mu{001B}[0m
let withoutStyles = styledString.uncolorized() // Terrible Combination

Disable leakage

The staining can be turned off globally:

String.isColorizationEnabled = false // Default: true

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

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

To disable coloring when running the program in the tube (./example | wc) or when there is no input to stdout (./example > output.txt) :

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

GitHub

swift interactive cliswift cli githubswiftline githubrainbow swift

You May Also Like

How To Fix Thumbnails Not Showing In Windows 10

The Windows thumbnail function makes it easy to recognize photos and movies…

A Complete Guide On Resolving The Issue of Phone Overheating

The phone can sometimes even get hot, whether it’s during a game…

How To Fix Windows 10 File Explorer Dark Theme Not Working

When it comes to customisation options, Windows 10 offers users a considerable…

Apex Legends Crashing PC Fix 2020

Various problems can occur during gambling. If you’re playing the new royal…