Swiftpack.co - OberstKrueger/OKTerminalColors as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by OberstKrueger.
OberstKrueger/OKTerminalColors 1.0.0
Terminal colors and styles for Swift CLI programs
⭐️ 0
🕓 9 weeks ago
.package(url: "https://github.com/OberstKrueger/OKTerminalColors.git", from: "1.0.0")

OKTerminalColors

This package allows printing of text to the terminal using standard ANSI escape codes. Foreground color, background color, and text styles are supported.

Usage

To print text with a specific foreground color, use the following:

import OKTerminalColors

let text = "Hello world!"

print(text.color(.red))

To print text with a specific background color, use the following:

import OKTerminalColors

let text = "Hello world!"

print(text.background(.yellow))

To print text with a specific style, use the following:

import OKTerminalColors

var text = "Hello world!"

print(text.style(.bold))

text = "Text can have multiple styles too."

print(text.style([.bold, .blink])

ANSI Reference Colors

The following ANSI terminal codes are used, and are referenced from https://en.wikipedia.org/wiki/ANSI_escape_code.

Style Code
Normal 0
Bold 1
Dim 2
Italic 3
Underline 4
Blink 5
Reverse 7
Coneal 8
Strike 9
Color Foreground Background
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47

GitHub

link
Stars: 0
Last commit: 9 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

9 weeks ago

1.0.0 release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics