Setup • Documentation • Release History
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.swift
file:
.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:
Submodule | Description |
---|---|
ANSIGraphics | Manipulates terminal display attributes through SGR (Select Graphic Rendition) parameters. |
ANSICursor | Provides methods to manipulate cursor posrc="https://raw.github.com/Riley229/SwiftANSI/master/n on console. |
ANSI Attributes are available as an extension to String
.
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 color(_:UInt8)
and 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()
String
methods more declarative in syntaxPackage.swift
link |
Stars: 0 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics