Skip to content
Myr

Do not print non-displayable characters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fzf used to print non-displayable characters (ascii code < 32) as '?', but we will simply ignore those characters with this patch, just like our terminals do. \n and \r are exceptions. They will be printed as a space character. TODO: \H should delete the preceding character, but this is not implemented.

authored by Junegunn Choi · committed by Junegunn Choi · parent 7dbbbef · Browse files · 2 files+13 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Related: #1253

Diff stats

2 files+13 added−10 removed

  • other:+13 added−10 removed

2 files+13 added−10 removed

modified:src/tui/light.go+8 added-6 removed
46 unmodified lines
47 bytes := []byte(str)48 runes := []rune{}49 for len(bytes) > 0 {50 r, sz := utf8.DecodeRune(bytes)51 nlcr := r == '\n' || r == '\r'51 if r == utf8.RuneError || r < 32 &&52 r != '\x1b' && (!allowNLCR || r != '\n' && r != '\r') {53 runes = append(runes, '?')54 } else {55 runes = append(runes, r)52 if r >= 32 || r == '\x1b' || nlcr {53 if r == utf8.RuneError || nlcr && !allowNLCR {54 runes = append(runes, ' ')55 } else {56 runes = append(runes, r)57 }58 }59 bytes = bytes[sz:]60 }61 r.queued += string(runes)
746 unmodified lines
808 w.cprint2(colDefault, w.bg, AttrRegular, text)809}810811func cleanse(str string) string {810 return strings.Replace(str, "\x1b", "?", -1)812 return strings.Replace(str, "\x1b", "", -1)813}814815func (w *LightWindow) CPrint(pair ColorPair, attr Attr, text string) {816 if !w.colored {
111 unmodified lines
modified:src/util/util.go+5 added-4 removed
15 unmodified lines
16 if r == '\t' {17 return tabstop - prefixWidth%tabstop18 } else if w, found := _runeWidths[r]; found {19 return w20 } else {21 w := Max(runewidth.RuneWidth(r), 1)22 _runeWidths[r] = w23 return w20 } else if r == '\n' || r == '\r' {21 return 122 }23 w := runewidth.RuneWidth(r)24 _runeWidths[r] = w25 return w26}2728// Max returns the largest integer29func Max(first int, second int) int {
85 unmodified lines