Skip to content

Commit

Permalink
Fix image previews containing long lines
Browse files Browse the repository at this point in the history
To reproduce, use `chafa --polite on -f symbols` for an image preview.
  • Loading branch information
joelim-work committed Jun 3, 2024
1 parent aaf5bbb commit f87bb29
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// size of its internal buffer
addLine := true
line := []byte{}
for len(reg.lines) < win.h {
line, isPrefix, err := reader.ReadLine()
bytes, isPrefix, err := reader.ReadLine()
if err != nil {
if len(line) > 0 {
reg.lines = append(reg.lines, string(line))
}
break
}

for _, r := range line {
if r == 0 {
for _, byte := range bytes {
if byte == 0 {
reg.lines = []string{"\033[7mbinary\033[0m"}
return
}
}

if addLine {
line = append(line, bytes...)

if !isPrefix {
reg.lines = append(reg.lines, string(line))
line = []byte{}
}

addLine = !isPrefix
}
}

Expand Down

0 comments on commit f87bb29

Please sign in to comment.