juri/terminal-ansi
This is a Swift package for outputting terminal ANSI control codes and inspecting the current terminal. It has been extracted and expanded from [tui-fuzzy-finder].
Usage
import TerminalANSI
guard let terminal = Terminal() else {
return
}
let isDark = try terminal.hasDarkBackground()
let size = try terminal.size()
terminal.writeCodes([
.clearScreen,
.moveCursor(x: size.width / 2, y: size.height / 2 - 6),
.setGraphicsRendition([
.textRGB(isDark ? RGBColor8(intR: 0xD0, g: 0x80, b: 0xC0) : RGBColor8(intR: 0x80, g: 0x30, b: 0x60)),
]),
.literal("Hello world!\n"),
.moveCursor(x: 0, y: size.height),
.setGraphicsRendition([
.reset,
])
])Features
- Queries:
- Terminal background and foreground colors - Size - Mouse pointer shapes
- Tools for determining terminal color support and user wishes based on the output device and the environment
- Parse color strings (
RGB,RRGGBB,RGBA,RRGGBBAA, with or without leading#) - Convert color to and from HSL
- Cursor movements, alternative buffer, erasing contents
- Colors, text styles
- Title (OSC 0)
- Hyperlinks (OSC 8)
- Terminal progress bar (OSC 9)
- Pointer shape (OSC 22)
[tui-fuzzy-finder]: https://github.com/juri/tui-fuzzy-finder/
Documentation
[Documentation] and Package.swift snippets are available at [Swift Package Index].
[Documentation]: https://swiftpackageindex.com/juri/terminal-ansi/documentation/terminalansi [Swift Package Index]: https://swiftpackageindex.com/juri/terminal-ansi
Package Metadata
Repository: juri/terminal-ansi
Default branch: main
README: README.md