martial-plains / swift-ansi-style

ANSI escape codes for styling strings in the terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AnsiStyle

AnsiStyle is a Swift library that provides a convenient way to style text in the terminal using ASCII escape codes. It offers options to apply different text colors, background colors, and text styles to enhance the appearance of text output in command-line interfaces.

Features

  • Apply various text colors and background colors to text.
  • Style text with bold, italic, underline, and other text styles.
  • Support for ANSI 256-color codes and RGB color values.
  • Easy-to-use API for applying styles to text.

Requirements

  • Swift 5.8+
  • Compatible with macOS, Linux, and other platforms that support Swift.

Installation

You can integrate AnsiStyle into your project using Swift Package Manager (SPM). Simply add it as a dependency in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/martial-plains/swift-ansi-style.git", branch: "main")
]

Usage

  1. Import the AnsiStyle module in your Swift file:
import AnsiStyle
  1. Create a TextStyler instance with the desired styles:
let styler = TextStyler(styles: [.color(color: .red), .bgColor(color: .white), .bold])
  1. Apply the styles to the desired text:
let stylizedText = styler.stylize(text: "Hello, Terminal!")
print(stylizedText)

The output will display the text "Hello, Terminal!" with red color, white background, and bold style.

License

AnsiStyle is released under the MIT License.

About

ANSI escape codes for styling strings in the terminal

License:MIT License


Languages

Language:Swift 100.0%