Fix image previews containing long lines (#1737)
To reproduce, use `chafa --polite on -f symbols` for an image preview.
This commit is contained in:
1 parent
aaf5bbb22b
commit
9b9082a10b
1 file changed
+12
-8
@@ -890,25 +890,29 @@ func (nav *nav) preview(path string, win *win) {
|
|||||||
|
|
||||||
// bufio.Scanner can't handle files containing long lines if they exceed the
|
// bufio.Scanner can't handle files containing long lines if they exceed the
|
||||||
// size of its internal buffer
|
// size of its internal buffer
|
||||||
addLine := true
|
line := []byte{}
|
||||||
for len(reg.lines) < win.h {
|
for len(reg.lines) < win.h {
|
||||||
line, isPrefix, err := reader.ReadLine()
|
bytes, isPrefix, err := reader.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if len(line) > 0 {
|
||||||
|
reg.lines = append(reg.lines, string(line))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range line {
|
for _, byte := range bytes {
|
||||||
if r == 0 {
|
if byte == 0 {
|
||||||
reg.lines = []string{"\033[7mbinary\033[0m"}
|
reg.lines = []string{"\033[7mbinary\033[0m"}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if addLine {
|
line = append(line, bytes...)
|
||||||
reg.lines = append(reg.lines, string(line))
|
|
||||||
}
|
|
||||||
|
|
||||||
addLine = !isPrefix
|
if !isPrefix {
|
||||||
|
reg.lines = append(reg.lines, string(line))
|
||||||
|
line = []byte{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user