Support ANSI escape sequence for clearing display in preview window

fzf --preview 'for i in $(seq 100000); do
    (( i % 200 == 0 )) && printf "\033[2J"
    echo "$i"
    sleep 0.01
  done'
This commit is contained in:
Junegunn Choi
2020-10-23 21:37:20 +09:00
parent e2b87e0d74
commit a4d9b0b468
4 changed files with 45 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ var numericPrefix *regexp.Regexp
var activeTempFiles []string
const ellipsis string = ".."
const clearCode string = "\x1b[2J"
func init() {
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)
@@ -1834,6 +1835,13 @@ func (t *Terminal) Loop() {
line := eachLine.line
err := eachLine.err
if len(line) > 0 {
clearIndex := strings.Index(line, clearCode)
if clearIndex >= 0 {
lines = []string{}
line = line[clearIndex+len(clearCode):]
version--
offset = 0
}
lines = append(lines, line)
}
if err != nil {