termtext is the one escaper of the kit. Text from elsewhere, such as the
output of a remote host, can move the cursor, retitle the terminal or show a
name in another order. termtext shows such characters as visible escapes.
It also measures text in the columns that a terminal gives it.
remote := "backup done\x1b]0;owned\x07\rbackup FAILED\n\tsee the log\n"
fmt.Print(termtext.EscapeLines(remote))backup done\x1b]0;owned\x07\rbackup FAILED
see the logtermtext/example_test.go. CI runs it and checks its output.The main names#
| Name | What it does |
|---|---|
termtext.Escape | one value on one line: newline and tab are escaped too |
termtext.EscapeLines | text of many lines: newline, tab and a CRLF line end stay |
termtext.NewEscapeWriter | a stream, escaped line by line as it comes |
termtext.Width | the columns of text: two for a wide rune, none for a mark |
termtext.Truncate | text cut to a number of columns, never inside a wide rune |
termtext.Wrap | a paragraph filled to a number of columns, with indents |
text := "Run the command on every host in the set, one after the other, and stop at the first failure."
fmt.Print(termtext.Wrap(text, 36, " -x, --exit ", " ")) -x, --exit Run the command on
every host in the set,
one after the other,
and stop at the first
failure.termtext/example_test.go. CI runs it and checks its output.Fixed interfaces#
- The forms of the escapes:
\r,\n,\t,\xNNand\uNNNN. - The CRLF rule (decision 42).
- The set of escaped runes can grow in a minor release (decision 14).
Read more#
Untrusted text explains the policy.