Documentation
¶
Overview ¶
Package termsafe makes text from outside the program, such as API responses, safe to print on a terminal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Stdout and Stderr are where plain text gets printed. Response data goes through the output formats instead, which render it from JSON. Like fmt.Println, they write to whatever os.Stdout and os.Stderr are at the time.
Functions ¶
func Escape ¶
Escape returns s with each non-graphic rune written as visible text, such as \x1b for ESC or \n for a newline, and each invalid byte as \xNN. Quotes, backslashes and joiners are unchanged, so ordinary text comes back as it was and escaping twice gives the same result as escaping once.
func JSON ¶
JSON rewrites encoded JSON so that no key or string in it decodes to text that Lines would change: such a rune becomes the escaped text instead, so `\u001b` becomes `\\x1b`. Valid JSON stays valid. JSON works on the text without parsing it, so a malformed document that a lenient decoder still reads comes out just as safe.