SwiftANSI is a set of lightweight Swift libraries allowing easy access to ANSI commands with declarative syntax.
SwiftANSI is distributed as a library through the Swift Package Manager. To use SwiftANSI or any of its submodules, simply add the following line to the dependencies in your
.package(url: "https://github.com/Riley229/SwiftANSI.git", from: "0.2.3")
Then, add SwiftANSI or the desired submodule(s) as a dependency for you target:
.target(name: "Demo", dependencies: [ .product(name: "ANSIGraphics", package: "SwiftANSI") ])
SwiftANSI contains the following submodules:
|ANSIGraphics||Manipulates terminal display attributes through SGR (Select Graphic Rendition) parameters.|
|ANSICursor||Provides methods to manipulate cursor position on console.|
ANSI Attributes are available as an extension to
To color text, simply follow the text with the desired color name. For example,
"test".red will output red text. Similarly, if you add the prefix
on to a color, you can manipulate the background text color. For instance,
"test".onBrightBlue will produce text on a bright blue background. In addition to the traditional 16 color system, ANSIGraphics also supports 8-bit colors. To use custom colors, use the
onColor(_:UInt8) methods for forground and background colors respectively.
You can also apply text styles by following the
String with a style name. For example,
"text".bold will produce bolded text. Attributes can also be chained e.g.
"text".brightYellow.underline will output bright yellow text which is underlined.
These are the available text styles (Note: not all systems support these styles):
ANSICursor provides various methods to manipulate the position of the cursor. These methods are provided through the
Cursor class as seen below:
static public func moveUp(_ lines: Int = 1) static public func moveDown(_ lines: Int = 1) static public func moveForward(_ lines: Int = 1) static public func moveBackward(_ lines: Int = 1) static public func moveUpLine(_ lines: Int = 1) static public func moveDownLine(_ lines: Int = 1) static public func setPosition(line: Int, column: Int) static public func savePosition() static public func restorePosition()
- 0.3.0: Remade ANSICursor as a more lightweight library and made major changes to README
- 0.2.3: Divided SwiftANSI into smaller modules and optimized internal calculations for ANSIStyle
- 0.2.2: Outsourced logging functionality to another library and made
Stringmethods more declarative in syntax
- 0.2.1: Removed functionality not operable on Ubuntu systems and updated documentation
- 0.2.0: Redesigned ANSI Interface and updated documentation
- 0.1.1: Corrected issue with
- 0.1.0: Initial release
You may find interesting
v0.3.0 - 2020-08-26T13:33:17
v0.2.3 - 2020-08-23T18:45:58
Added SwiftANSI submodules!
- Added italic as a text attribute
- Adjusted Color to handle bright color code calculation
- Optimized String styling and reduced code redundancy
SwiftANSI Pre-release v0.2.2 - 2020-05-09T04:12:30
With the logging system being outsourced to another project, SwiftANSI is focused purely on creating easy to use and understand ANSI commands. Strings are now easier to format with less code.
ConsoleLog Alpha 0.2.1 - 2020-05-07T00:45:35
Optimized ANSI classes and made more Linux-compatible. See README for extended ANSI methods
ConsoleLog Alpha 0.2.0 - 2020-05-06T20:39:46
Increased ANSI functionality by adding in additional formatting tools as well as creating an ANSIEnables protocol for easier ANSI conformation.
ConsoleLog Alpha 0.1.1 - 2020-05-05T22:20:49
ConsoleLog Alpha 0.1.0 - 2020-05-05T21:56:31
Does not work on some systems at the moment.