m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 07:13:48 -05:00

Implement multi-line display of multi-line items

This commit is contained in:
Junegunn Choi
2024-05-20 01:33:33 +09:00
parent 5b204c54f9
commit 04db44067d
6 changed files with 411 additions and 187 deletions

View File

@@ -1,6 +1,7 @@
package util
import (
"bytes"
"fmt"
"unicode"
"unicode/utf8"
@@ -74,6 +75,35 @@ func (chars *Chars) Bytes() []byte {
return chars.slice
}
func (chars *Chars) NumLines(atMost int) int {
lines := 1
if runes := chars.optionalRunes(); runes != nil {
for _, r := range runes {
if r == '\n' {
lines++
}
if lines >= atMost {
return atMost
}
}
return lines
}
for idx := 0; idx < len(chars.slice); idx++ {
found := bytes.IndexByte(chars.slice[idx:], '\n')
if found < 0 {
break
}
idx += found
lines++
if lines >= atMost {
return atMost
}
}
return lines
}
func (chars *Chars) optionalRunes() []rune {
if chars.inBytes {
return nil