Implement builtin support for sixel images, allow combining with text (#2109)
* Add function for reading lines in file * Implement sixel drawing * Remove sixel option * Fix linting error
This commit is contained in:
1 parent
aba73884e3
commit
13da770af6
11 files changed
+190
-99
No files matched your search
@@ -12,7 +12,6 @@ import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -914,43 +913,12 @@ func (nav *nav) preview(path string, win *win) {
|
||||
reader = bufio.NewReader(f)
|
||||
}
|
||||
|
||||
if gOpts.sixel {
|
||||
prefix, err := reader.Peek(2)
|
||||
if err == nil && string(prefix) == gSixelBegin {
|
||||
b, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
log.Printf("loading sixel: %s", err)
|
||||
}
|
||||
str := string(b)
|
||||
reg.sixel = &str
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// bufio.Scanner can't handle files containing long lines if they exceed the
|
||||
// size of its internal buffer
|
||||
line := []byte{}
|
||||
for len(reg.lines) < win.h {
|
||||
bytes, isPrefix, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
if len(line) > 0 {
|
||||
reg.lines = append(reg.lines, string(line))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if slices.Contains(bytes, 0) {
|
||||
reg.lines = []string{"\033[7mbinary\033[0m"}
|
||||
return
|
||||
}
|
||||
|
||||
line = append(line, bytes...)
|
||||
|
||||
if !isPrefix {
|
||||
reg.lines = append(reg.lines, string(line))
|
||||
line = []byte{}
|
||||
}
|
||||
lines, binary, sixel := readLines(reader, win.h)
|
||||
if binary {
|
||||
lines = []string{"\033[7mbinary\033[0m"}
|
||||
}
|
||||
reg.lines = lines
|
||||
reg.sixel = sixel
|
||||
}
|
||||
|
||||
func (nav *nav) loadReg(path string, volatile bool) *reg {
|
||||
|
||||
Reference in new issue
Block a user