diff options
| author | Eric Biggers <ebiggers@google.com> | 2020-05-09 15:27:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-09 15:27:24 -0700 |
| commit | d4d28232d32bfb3f4827fcb79bd5043e1932ae66 (patch) | |
| tree | dda5a65b2d8c157e03d3d35f3442547dafd51e4c /cmd/fscrypt/format.go | |
| parent | 1cdefc21b8b07aad7aafeefd05d3124cf93b9216 (diff) | |
| parent | 181600d6327ed34a3f62eda0dd03a6d2ae49e5f9 (diff) | |
Merge pull request #219 from ebiggers/improve-errors
Improve error messages and suggestions
Diffstat (limited to 'cmd/fscrypt/format.go')
| -rw-r--r-- | cmd/fscrypt/format.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cmd/fscrypt/format.go b/cmd/fscrypt/format.go index cc268aa..576d025 100644 --- a/cmd/fscrypt/format.go +++ b/cmd/fscrypt/format.go @@ -121,7 +121,8 @@ func longDisplay(f prettyFlag, defaultString ...string) string { // Takes an input string text, and wraps the text so that each line begins with // padding spaces (except for the first line), ends with a newline (except the // last line), and each line has length less than lineLength. If the text -// contains a word which is too long, that word gets its own line. +// contains a word which is too long, that word gets its own line. Paragraphs +// and "code blocks" are preserved. func wrapText(text string, padding int) string { // We use a buffer to format the wrapped text so we get O(n) runtime var buffer bytes.Buffer @@ -141,10 +142,18 @@ func wrapText(text string, padding int) string { continue } + codeBlock := (words[0] == ">") + if codeBlock { + words[0] = " " + if filled != 0 { + buffer.WriteString("\n") + filled = 0 + } + } for _, word := range words { wordLen := utf8.RuneCountInString(word) // Write a newline if needed. - if filled != 0 && filled+1+wordLen > lineLength { + if filled != 0 && filled+1+wordLen > lineLength && !codeBlock { buffer.WriteString("\n") filled = 0 } |