oakcitylabs/ansi2html
A Swift library to convert text with ANSI escape codes to HTML.
Usages
Direct Usage
You can create a string builder and use the conversion method directly on the builder.
import Ansi2Html
let builder = AnsiHtmlStringBuilder()
if builder.stringHasAnsi(stringWithAnsiCodes) {
let html = builder.stringToHtml(stringWithAnsiCodes)
}String Extension
It may be more useful to add an extension on string for convenience.
import Ansi2Html
private let builder = AnsiHtmlStringBuilder()
extension String {
var ansiToHtml: String {
guard hasAnsi else { return self }
return builder.stringToHtml(self)
}
var hasAnsi: Bool {
builder.stringHasAnsi(self)
}
}Elsewhere in your code you can use the ansiToHtml computed attribute.
let html = stringWithAnsiCodes.ansiToHtml
Package Metadata
Repository: oakcitylabs/ansi2html
Default branch: main
README: README.md