tts

main

Terminal Text Style
andrsem/tts

tts logo

Getting Started

To use TTS - Terminal Text Style in a SwiftPM project, add it as a package dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/andrsem/tts.git", from: "1.0.0")
]

Then, adding the Terminal Text Style module to your target dependencies:

.target(
    name: "MyTarget",
    dependencies: [
        .product(name: "TTS", package: "TTS")
    ]
)

Examples

Basic color (16-color palette)

basic color

print("Red foreground".fg(.red))
print("Yellow bg, black fg".fg(.black).bg(.yellow))

Extended color (256-color palette)

extended color

print("Extended fg (135)".fg(135))
print("Extended bg (244)".bg(244))

Color model foreground color

color model foreground

print("RGB color fg (120, 11, 250)".fg(.rgb(120, 11, 250)))
print("HSB color fg (320, 0.6, 0.8)".fg(.hsb(320, 0.6, 0.8)))
print("HEX color fg (#BFBFBF)".fg(.hex("#BFBFBF")))

Color model background color

color model background

print("RGB color bg (120, 11, 250)".bg(.rgb(120, 11, 250)))
print("HSB color bg (320, 0.6, 0.8)".bg(.hsb(320, 0.6, 0.8)))
print("HEX color bg (#BFBFBF)".bg(.hex("#BFBFBF")))

Foreground and background colors with styles

fg and bg with styles

let styledStr = "Styled fg and bg; bold, italic"
   .fg(.blue)
   .bg(.rgb(255, 200, 0))
   .styles(.bold, .italic)

print(styledStr)

Manual resetting styles

multiple resets

let resetedStr =
   "bold underline, "
   .fg(.red, reset: .manual)
   .styles(.bold, .underline, reset: .manual)
   + "bold, ".reset(.underline, .before)
   + "red, ".reset(.bold, .before).reset(.fgColor)
   + "normal"

print(resetedStr)

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Jul 13 2026 02:07:42 GMT-0900 (Hawaii-Aleutian Daylight Time)