Skip to content
Snippets Groups Projects
Unverified Commit f57920ad authored by Junegunn Choi's avatar Junegunn Choi
Browse files

Do not print non-displayable characters

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.

Related: #1253
parent 7dbbbef5
No related branches found
No related tags found
No related merge requests found
...@@ -48,11 +48,13 @@ func (r *LightRenderer) stderrInternal(str string, allowNLCR bool) { ...@@ -48,11 +48,13 @@ func (r *LightRenderer) stderrInternal(str string, allowNLCR bool) {
runes := []rune{} runes := []rune{}
for len(bytes) > 0 { for len(bytes) > 0 {
r, sz := utf8.DecodeRune(bytes) r, sz := utf8.DecodeRune(bytes)
if r == utf8.RuneError || r < 32 && nlcr := r == '\n' || r == '\r'
r != '\x1b' && (!allowNLCR || r != '\n' && r != '\r') { if r >= 32 || r == '\x1b' || nlcr {
runes = append(runes, '?') if r == utf8.RuneError || nlcr && !allowNLCR {
} else { runes = append(runes, ' ')
runes = append(runes, r) } else {
runes = append(runes, r)
}
} }
bytes = bytes[sz:] bytes = bytes[sz:]
} }
...@@ -807,7 +809,7 @@ func (w *LightWindow) Print(text string) { ...@@ -807,7 +809,7 @@ func (w *LightWindow) Print(text string) {
} }
func cleanse(str string) string { func cleanse(str string) string {
return strings.Replace(str, "\x1b", "?", -1) return strings.Replace(str, "\x1b", "", -1)
} }
func (w *LightWindow) CPrint(pair ColorPair, attr Attr, text string) { func (w *LightWindow) CPrint(pair ColorPair, attr Attr, text string) {
......
...@@ -17,11 +17,12 @@ func RuneWidth(r rune, prefixWidth int, tabstop int) int { ...@@ -17,11 +17,12 @@ func RuneWidth(r rune, prefixWidth int, tabstop int) int {
return tabstop - prefixWidth%tabstop return tabstop - prefixWidth%tabstop
} else if w, found := _runeWidths[r]; found { } else if w, found := _runeWidths[r]; found {
return w return w
} else { } else if r == '\n' || r == '\r' {
w := Max(runewidth.RuneWidth(r), 1) return 1
_runeWidths[r] = w
return w
} }
w := runewidth.RuneWidth(r)
_runeWidths[r] = w
return w
} }
// Max returns the largest integer // Max returns the largest integer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment