mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-12 21:33:49 -05:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
535b610a6b | ||
|
|
91fab3b3c2 | ||
|
|
b9f2bf64ff | ||
|
|
07d53cb7e4 | ||
|
|
ead534a1be | ||
|
|
8a05083503 | ||
|
|
e659b46ff5 | ||
|
|
991c36453c | ||
|
|
4d563c6dfa | ||
|
|
5cb695744f |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -33,12 +33,12 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
uses: github/codeql-action/analyze@v4
|
||||
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,6 +1,24 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
0.67.0
|
||||
------
|
||||
- Added `--freeze-left=N` option to keep the leftmost N columns visible.
|
||||
```sh
|
||||
# Keeps the file name column fixed and always visible
|
||||
git grep --line-number --color=always -- '' |
|
||||
fzf --ansi --delimiter : --freeze-left 1
|
||||
|
||||
# Used with --keep-right
|
||||
git grep --line-number --color=always -- '' |
|
||||
fzf --ansi --delimiter : --freeze-left 1 --keep-right
|
||||
```
|
||||
- Also added `--freeze-right=N` option to keep the rightmost N columns visible.
|
||||
```sh
|
||||
fd | fzf --freeze-right 1 --delimiter /
|
||||
fd | fzf --freeze-left 1 --freeze-right 1 --delimiter /
|
||||
```
|
||||
|
||||
0.66.1
|
||||
------
|
||||
- Bug fixes
|
||||
|
||||
@@ -629,9 +629,16 @@ Render empty lines between each item
|
||||
The given string will be repeated to draw a horizontal line on each gap
|
||||
(default: '┈' or '\-' depending on \fB\-\-no\-unicode\fR).
|
||||
.TP
|
||||
.BI "\-\-freeze\-left=" "N"
|
||||
Number of fields to freeze on the left.
|
||||
.TP
|
||||
.BI "\-\-freeze\-right=" "N"
|
||||
Number of fields to freeze on the right.
|
||||
.TP
|
||||
.B "\-\-keep\-right"
|
||||
Keep the right end of the line visible when it's too long. Effective only when
|
||||
the query string is empty.
|
||||
the query string is empty. Use \fB\-\-freeze\-right=1\fR instead if you want
|
||||
the last field to be always visible even with a non-empty query.
|
||||
.TP
|
||||
.BI "\-\-scroll\-off=" "LINES"
|
||||
Number of screen lines to keep above or below when scrolling to the top or to
|
||||
@@ -651,6 +658,9 @@ Label characters for \fBjump\fR mode.
|
||||
.BI "\-\-gutter=" "CHAR"
|
||||
Character used for the gutter column (default: '▌' unless \fB\-\-no\-unicode\fR is given)
|
||||
.TP
|
||||
.BI "\-\-gutter\-raw=" "CHAR"
|
||||
Character used for the gutter column in raw mode (default: '▖' unless \fB\-\-no\-unicode\fR is given)
|
||||
.TP
|
||||
.BI "\-\-pointer=" "STR"
|
||||
Pointer to the current line (default: '▌' or '>' depending on \fB\-\-no\-unicode\fR)
|
||||
.TP
|
||||
|
||||
@@ -26,7 +26,10 @@ __fzf_exec_awk() {
|
||||
# version >= 1.3.4
|
||||
local n x y z d
|
||||
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||
[[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
|
||||
[[ $n == mawk ]] &&
|
||||
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
||||
((d >= 20230302)) 2> /dev/null &&
|
||||
__fzf_awk=mawk
|
||||
fi
|
||||
fi
|
||||
# Note: macOS awk has a quirk that it stops processing at all when it sees
|
||||
|
||||
@@ -51,7 +51,10 @@ __fzf_exec_awk() {
|
||||
elif command -v mawk > /dev/null 2>&1; then
|
||||
local n x y z d
|
||||
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||
[[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
|
||||
[[ $n == mawk ]] &&
|
||||
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
||||
((d >= 20230302)) 2> /dev/null &&
|
||||
__fzf_awk=mawk
|
||||
fi
|
||||
fi
|
||||
LC_ALL=C exec "$__fzf_awk" "$@"
|
||||
|
||||
@@ -115,7 +115,10 @@ __fzf_exec_awk() {
|
||||
elif command -v mawk > /dev/null 2>&1; then
|
||||
local n x y z d
|
||||
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||
[[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
|
||||
[[ $n == mawk ]] &&
|
||||
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
||||
((d >= 20230302)) 2> /dev/null &&
|
||||
__fzf_awk=mawk
|
||||
fi
|
||||
fi
|
||||
LC_ALL=C exec "$__fzf_awk" "$@"
|
||||
|
||||
@@ -38,7 +38,10 @@ __fzf_exec_awk() {
|
||||
elif command -v mawk > /dev/null 2>&1; then
|
||||
local n x y z d
|
||||
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||
[[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
|
||||
[[ $n == mawk ]] &&
|
||||
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
||||
((d >= 20230302)) 2> /dev/null &&
|
||||
__fzf_awk=mawk
|
||||
fi
|
||||
fi
|
||||
LC_ALL=C exec "$__fzf_awk" "$@"
|
||||
|
||||
@@ -58,7 +58,10 @@ __fzf_exec_awk() {
|
||||
elif command -v mawk > /dev/null 2>&1; then
|
||||
local n x y z d
|
||||
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||
[[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
|
||||
[[ $n == mawk ]] &&
|
||||
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&
|
||||
((d >= 20230302)) 2> /dev/null &&
|
||||
__fzf_awk=mawk
|
||||
fi
|
||||
fi
|
||||
LC_ALL=C exec "$__fzf_awk" "$@"
|
||||
|
||||
@@ -365,7 +365,7 @@ func asciiFuzzyIndex(input *util.Chars, pattern []rune, caseSensitive bool) (int
|
||||
|
||||
firstIdx, idx, lastIdx := 0, 0, 0
|
||||
var b byte
|
||||
for pidx := 0; pidx < len(pattern); pidx++ {
|
||||
for pidx := range pattern {
|
||||
b = byte(pattern[pidx])
|
||||
idx = trySkip(input, caseSensitive, b, idx)
|
||||
if idx < 0 {
|
||||
@@ -726,7 +726,7 @@ func FuzzyMatchV1(caseSensitive bool, normalize bool, forward bool, text *util.C
|
||||
lenRunes := text.Length()
|
||||
lenPattern := len(pattern)
|
||||
|
||||
for index := 0; index < lenRunes; index++ {
|
||||
for index := range lenRunes {
|
||||
char := text.Get(indexAt(index, lenRunes, forward))
|
||||
// This is considerably faster than blindly applying strings.ToLower to the
|
||||
// whole string
|
||||
|
||||
@@ -41,7 +41,7 @@ func testParserReference(t testing.TB, str string) {
|
||||
|
||||
equal := len(got) == len(exp)
|
||||
if equal {
|
||||
for i := 0; i < len(got); i++ {
|
||||
for i := range got {
|
||||
if got[i] != exp[i] {
|
||||
equal = false
|
||||
break
|
||||
@@ -167,9 +167,9 @@ func TestNextAnsiEscapeSequence_Fuzz_Random(t *testing.T) {
|
||||
randomString := func(rr *rand.Rand) string {
|
||||
numChars := rand.Intn(50)
|
||||
codePoints := make([]rune, numChars)
|
||||
for i := 0; i < len(codePoints); i++ {
|
||||
for i := range codePoints {
|
||||
var r rune
|
||||
for n := 0; n < 1000; n++ {
|
||||
for range 1000 {
|
||||
r = rune(rr.Intn(utf8.MaxRune))
|
||||
// Allow 10% of runes to be invalid
|
||||
if utf8.ValidRune(r) || rr.Float64() < 0.10 {
|
||||
@@ -182,7 +182,7 @@ func TestNextAnsiEscapeSequence_Fuzz_Random(t *testing.T) {
|
||||
}
|
||||
|
||||
rr := rand.New(rand.NewSource(1))
|
||||
for i := 0; i < 100_000; i++ {
|
||||
for range 100_000 {
|
||||
testParserReference(t, randomString(rr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestChunkList(t *testing.T) {
|
||||
}
|
||||
|
||||
// Add more data
|
||||
for i := 0; i < chunkSize*2; i++ {
|
||||
for i := range chunkSize * 2 {
|
||||
cl.Push(fmt.Appendf(nil, "item %d", i))
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func TestChunkListTail(t *testing.T) {
|
||||
return true
|
||||
})
|
||||
total := chunkSize*2 + chunkSize/2
|
||||
for i := 0; i < total; i++ {
|
||||
for i := range total {
|
||||
cl.Push(fmt.Appendf(nil, "item %d", i))
|
||||
}
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ func Run(opts *Options) (int, error) {
|
||||
return item.acceptNth(opts.Ansi, opts.Delimiter, fn)
|
||||
}
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
for i := range count {
|
||||
opts.Printer(transformer(merger.Get(i).item))
|
||||
}
|
||||
if count == 0 {
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestHistory(t *testing.T) {
|
||||
if len(h.lines) != maxHistory+1 {
|
||||
t.Errorf("Expected: %d, actual: %d\n", maxHistory+1, len(h.lines))
|
||||
}
|
||||
for i := 0; i < maxHistory; i++ {
|
||||
for i := range maxHistory {
|
||||
if h.lines[i] != "foobar" {
|
||||
t.Error("Expected: foobar, actual: " + h.lines[i])
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ func buildLists(partiallySorted bool) ([][]Result, []Result) {
|
||||
numLists := 4
|
||||
lists := make([][]Result, numLists)
|
||||
cnt := 0
|
||||
for i := 0; i < numLists; i++ {
|
||||
for i := range numLists {
|
||||
numResults := rand.Int() % 20
|
||||
cnt += numResults
|
||||
lists[i] = make([]Result, numResults)
|
||||
for j := 0; j < numResults; j++ {
|
||||
for j := range numResults {
|
||||
item := randResult()
|
||||
lists[i][j] = item
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func TestMergerUnsorted(t *testing.T) {
|
||||
// Not sorted: same order
|
||||
mg := NewMerger(nil, lists, false, false, revision{}, 0, 0)
|
||||
assert(t, cnt == mg.Length(), "Invalid Length")
|
||||
for i := 0; i < cnt; i++ {
|
||||
for i := range cnt {
|
||||
assert(t, items[i] == mg.Get(i), "Invalid Get")
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func TestMergerSorted(t *testing.T) {
|
||||
mg := NewMerger(nil, lists, true, false, revision{}, 0, 0)
|
||||
assert(t, cnt == mg.Length(), "Invalid Length")
|
||||
sort.Sort(ByRelevance(items))
|
||||
for i := 0; i < cnt; i++ {
|
||||
for i := range cnt {
|
||||
if items[i] != mg.Get(i) {
|
||||
t.Error("Not sorted", items[i], mg.Get(i))
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ Usage: fzf [options]
|
||||
--gap[=N] Render empty lines between each item
|
||||
--gap-line[=STR] Draw horizontal line on each gap using the string
|
||||
(default: '┈' or '-')
|
||||
--freeze-left=N Number of fields to freeze on the left
|
||||
--freeze-right=N Number of fields to freeze on the right
|
||||
--keep-right Keep the right end of the line visible on overflow
|
||||
--scroll-off=LINES Number of screen lines to keep above or below when
|
||||
scrolling to the top or to the bottom (default: 0)
|
||||
@@ -562,6 +564,8 @@ type Options struct {
|
||||
Case Case
|
||||
Normalize bool
|
||||
Nth []Range
|
||||
FreezeLeft int
|
||||
FreezeRight int
|
||||
WithNth func(Delimiter) func([]Token, int32) string
|
||||
AcceptNth func(Delimiter) func([]Token, int32) string
|
||||
Delimiter Delimiter
|
||||
@@ -2695,6 +2699,14 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
||||
if opts.Nth, err = splitNth(str); err != nil {
|
||||
return err
|
||||
}
|
||||
case "--freeze-left":
|
||||
if opts.FreezeLeft, err = nextInt("number of fields required"); err != nil {
|
||||
return err
|
||||
}
|
||||
case "--freeze-right":
|
||||
if opts.FreezeRight, err = nextInt("number of fields required"); err != nil {
|
||||
return err
|
||||
}
|
||||
case "--with-nth":
|
||||
str, err := nextString("nth expression required")
|
||||
if err != nil {
|
||||
@@ -3338,6 +3350,10 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
||||
return errors.New("empty jump labels")
|
||||
}
|
||||
|
||||
if opts.FreezeLeft < 0 || opts.FreezeRight < 0 {
|
||||
return errors.New("number of fields to freeze must be a non-negative integer")
|
||||
}
|
||||
|
||||
if validateJumpLabels {
|
||||
for _, r := range opts.JumpLabels {
|
||||
if r < 32 || r > 126 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -178,7 +179,7 @@ func (r *Reader) feed(src io.Reader) {
|
||||
for {
|
||||
n := 0
|
||||
scope := slab[:util.Min(len(slab), readerBufferSize)]
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
n, err = src.Read(scope)
|
||||
if n > 0 || err != nil {
|
||||
break
|
||||
@@ -308,15 +309,11 @@ func (r *Reader) readFiles(roots []string, opts walkerOpts, ignores []string) bo
|
||||
if !opts.hidden && base[0] == '.' && base != ".." {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
for _, ignore := range ignoresBase {
|
||||
if ignore == base {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if slices.Contains(ignoresBase, base) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
for _, ignore := range ignoresFull {
|
||||
if ignore == path {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if slices.Contains(ignoresFull, path) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
for _, ignore := range ignoresSuffix {
|
||||
if strings.HasSuffix(path, ignore) {
|
||||
|
||||
@@ -91,7 +91,7 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
|
||||
case byBegin, byEnd:
|
||||
if validOffsetFound {
|
||||
whitePrefixLen := 0
|
||||
for idx := 0; idx < numChars; idx++ {
|
||||
for idx := range numChars {
|
||||
r := item.text.Get(idx)
|
||||
whitePrefixLen = idx
|
||||
if idx == minBegin || !unicode.IsSpace(r) {
|
||||
|
||||
221
src/terminal.go
221
src/terminal.go
@@ -331,6 +331,8 @@ type Terminal struct {
|
||||
scrollbar string
|
||||
previewScrollbar string
|
||||
ansi bool
|
||||
freezeLeft int
|
||||
freezeRight int
|
||||
nthAttr tui.Attr
|
||||
nth []Range
|
||||
nthCurrent []Range
|
||||
@@ -496,6 +498,14 @@ const (
|
||||
reqFatal
|
||||
)
|
||||
|
||||
func isTerminalEvent(et util.EventType) bool {
|
||||
switch et {
|
||||
case reqClose, reqPrintQuery, reqBecome, reqQuit, reqFatal:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type action struct {
|
||||
t actionType
|
||||
a string
|
||||
@@ -1050,6 +1060,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
||||
footer: opts.Footer,
|
||||
header0: opts.Header,
|
||||
ansi: opts.Ansi,
|
||||
freezeLeft: opts.FreezeLeft,
|
||||
freezeRight: opts.FreezeRight,
|
||||
nthAttr: opts.Theme.Nth.Attr,
|
||||
nth: opts.Nth,
|
||||
nthCurrent: opts.Nth,
|
||||
@@ -2981,6 +2993,11 @@ func (t *Terminal) printInfoImpl() {
|
||||
} else {
|
||||
outputPrinter(t.window, maxWidth)
|
||||
}
|
||||
if t.infoStyle == infoInline && outputLen < maxWidth-1 && t.reading {
|
||||
t.window.Print(" ")
|
||||
printSpinner()
|
||||
outputLen += 2
|
||||
}
|
||||
|
||||
if t.infoStyle == infoInlineRight {
|
||||
if t.separatorLen > 0 {
|
||||
@@ -3509,17 +3526,46 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
} else {
|
||||
tokens = Transform(Tokenize(item.text.ToString(), t.delimiter), t.nthCurrent)
|
||||
}
|
||||
for _, token := range tokens {
|
||||
nthOffsets = make([]Offset, len(tokens))
|
||||
for i, token := range tokens {
|
||||
start := token.prefixLength
|
||||
length := token.text.Length() - token.text.TrailingWhitespaces()
|
||||
end := start + int32(length)
|
||||
nthOffsets = append(nthOffsets, Offset{int32(start), int32(end)})
|
||||
nthOffsets[i] = Offset{int32(start), int32(end)}
|
||||
}
|
||||
sort.Sort(ByOrder(nthOffsets))
|
||||
}
|
||||
}
|
||||
allOffsets := result.colorOffsets(charOffsets, nthOffsets, t.theme, colBase, colMatch, t.nthAttr, hidden)
|
||||
|
||||
// Determine split offset for horizontal scrolling with freeze
|
||||
splitOffset1 := -1
|
||||
splitOffset2 := -1
|
||||
if t.hscroll && !t.wrap {
|
||||
var tokens []Token
|
||||
if t.freezeLeft > 0 || t.freezeRight > 0 {
|
||||
tokens = Tokenize(item.text.ToString(), t.delimiter)
|
||||
}
|
||||
// 0 1 2| 3 |4 5
|
||||
// -----> <---
|
||||
if t.freezeLeft > 0 {
|
||||
if len(tokens) > 0 {
|
||||
token := tokens[util.Min(t.freezeLeft, len(tokens))-1]
|
||||
splitOffset1 = int(token.prefixLength) + token.text.Length() - token.text.TrailingWhitespaces()
|
||||
}
|
||||
}
|
||||
if t.freezeRight > 0 {
|
||||
index := util.Max(t.freezeLeft-1, len(tokens)-t.freezeRight-1)
|
||||
if index < 0 {
|
||||
splitOffset2 = 0
|
||||
} else if index >= t.freezeLeft {
|
||||
token := tokens[index]
|
||||
splitOffset2 = int(token.prefixLength) + token.text.Length()
|
||||
}
|
||||
splitOffset2 = util.Max(splitOffset2, splitOffset1)
|
||||
}
|
||||
}
|
||||
|
||||
maxLines := 1
|
||||
if t.canSpanMultiLines() {
|
||||
maxLines = maxLineNum - lineNum + 1
|
||||
@@ -3589,16 +3635,24 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
break
|
||||
}
|
||||
}
|
||||
splitOffsetLeft := 0
|
||||
if splitOffset1 >= 0 && splitOffset1 > from && splitOffset1 < from+len(line) {
|
||||
splitOffsetLeft = splitOffset1 - from
|
||||
}
|
||||
splitOffsetRight := -1
|
||||
if splitOffset2 >= 0 && splitOffset2 >= from && splitOffset2 < from+len(line) {
|
||||
splitOffsetRight = splitOffset2 - from
|
||||
}
|
||||
from += len(line)
|
||||
if lineOffset < skipLines {
|
||||
continue
|
||||
}
|
||||
actualLineOffset := lineOffset - skipLines
|
||||
|
||||
var maxe int
|
||||
var maxEnd int
|
||||
for _, offset := range offsets {
|
||||
if offset.match {
|
||||
maxe = util.Max(maxe, int(offset.offset[1]))
|
||||
maxEnd = util.Max(maxEnd, int(offset.offset[1]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3662,69 +3716,112 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
wrapped = true
|
||||
}
|
||||
|
||||
displayWidth = t.displayWidthWithLimit(line, 0, maxWidth)
|
||||
if !t.wrap && displayWidth > maxWidth {
|
||||
ellipsis, ellipsisWidth := util.Truncate(t.ellipsis, maxWidth/2)
|
||||
maxe = util.Constrain(maxe+util.Min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(line))
|
||||
transformOffsets := func(diff int32, rightTrim bool) {
|
||||
for idx, offset := range offsets {
|
||||
b, e := offset.offset[0], offset.offset[1]
|
||||
el := int32(len(ellipsis))
|
||||
b += el - diff
|
||||
e += el - diff
|
||||
b = util.Max32(b, el)
|
||||
if rightTrim {
|
||||
e = util.Min32(e, int32(maxWidth-ellipsisWidth))
|
||||
}
|
||||
offsets[idx].offset[0] = b
|
||||
offsets[idx].offset[1] = util.Max32(b, e)
|
||||
}
|
||||
frozenLeft := line[:splitOffsetLeft]
|
||||
middle := line[splitOffsetLeft:]
|
||||
frozenRight := []rune{}
|
||||
if splitOffsetRight >= splitOffsetLeft {
|
||||
middle = line[splitOffsetLeft:splitOffsetRight]
|
||||
frozenRight = line[splitOffsetRight:]
|
||||
}
|
||||
displayWidthSum := 0
|
||||
todo := [3]func(){}
|
||||
for fidx, runes := range [][]rune{frozenLeft, frozenRight, middle} {
|
||||
if len(runes) == 0 {
|
||||
continue
|
||||
}
|
||||
if t.hscroll {
|
||||
if t.keepRight && pos == nil {
|
||||
trimmed, diff := t.trimLeft(line, maxWidth, ellipsisWidth)
|
||||
transformOffsets(diff, false)
|
||||
line = append(ellipsis, trimmed...)
|
||||
} else if !t.overflow(line[:maxe], maxWidth-ellipsisWidth) {
|
||||
// Stri..
|
||||
line, _ = t.trimRight(line, maxWidth-ellipsisWidth)
|
||||
line = append(line, ellipsis...)
|
||||
} else {
|
||||
// Stri..
|
||||
rightTrim := false
|
||||
if t.overflow(line[maxe:], ellipsisWidth) {
|
||||
line = append(line[:maxe], ellipsis...)
|
||||
rightTrim = true
|
||||
shift := 0
|
||||
maxe := maxEnd
|
||||
offs := make([]colorOffset, len(offsets))
|
||||
for idx := range offsets {
|
||||
offs[idx] = offsets[idx]
|
||||
if fidx == 1 && splitOffsetRight > 0 {
|
||||
shift = splitOffsetRight
|
||||
} else if fidx == 2 && splitOffsetLeft > 0 {
|
||||
shift = splitOffsetLeft
|
||||
}
|
||||
offs[idx].offset[0] -= int32(shift)
|
||||
offs[idx].offset[1] -= int32(shift)
|
||||
}
|
||||
maxe -= shift
|
||||
displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth)
|
||||
if !t.wrap && displayWidth > maxWidth {
|
||||
ellipsis, ellipsisWidth := util.Truncate(t.ellipsis, maxWidth/2)
|
||||
maxe = util.Constrain(maxe+util.Min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))
|
||||
transformOffsets := func(diff int32, rightTrim bool) {
|
||||
for idx, offset := range offs {
|
||||
b, e := offset.offset[0], offset.offset[1]
|
||||
el := int32(len(ellipsis))
|
||||
b += el - diff
|
||||
e += el - diff
|
||||
b = util.Max32(b, el)
|
||||
if rightTrim {
|
||||
e = util.Min32(e, int32(maxWidth-ellipsisWidth))
|
||||
}
|
||||
offs[idx].offset[0] = b
|
||||
offs[idx].offset[1] = util.Max32(b, e)
|
||||
}
|
||||
// ..ri..
|
||||
var diff int32
|
||||
line, diff = t.trimLeft(line, maxWidth, ellipsisWidth)
|
||||
}
|
||||
if t.hscroll {
|
||||
if fidx == 1 || fidx == 2 && t.keepRight && pos == nil {
|
||||
trimmed, diff := t.trimLeft(runes, maxWidth, ellipsisWidth)
|
||||
transformOffsets(diff, false)
|
||||
runes = append(ellipsis, trimmed...)
|
||||
} else if fidx == 0 || !t.overflow(runes[:maxe], maxWidth-ellipsisWidth) {
|
||||
// Stri..
|
||||
runes, _ = t.trimRight(runes, maxWidth-ellipsisWidth)
|
||||
runes = append(runes, ellipsis...)
|
||||
} else {
|
||||
// Stri..
|
||||
rightTrim := false
|
||||
if t.overflow(runes[maxe:], ellipsisWidth) {
|
||||
runes = append(runes[:maxe], ellipsis...)
|
||||
rightTrim = true
|
||||
}
|
||||
// ..ri..
|
||||
var diff int32
|
||||
runes, diff = t.trimLeft(runes, maxWidth, ellipsisWidth)
|
||||
|
||||
// Transform offsets
|
||||
transformOffsets(diff, rightTrim)
|
||||
line = append(ellipsis, line...)
|
||||
// Transform offsets
|
||||
transformOffsets(diff, rightTrim)
|
||||
runes = append(ellipsis, runes...)
|
||||
}
|
||||
} else {
|
||||
runes, _ = t.trimRight(runes, maxWidth-ellipsisWidth)
|
||||
runes = append(runes, ellipsis...)
|
||||
|
||||
for idx, offset := range offs {
|
||||
offs[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-len(ellipsis)))
|
||||
offs[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))
|
||||
}
|
||||
}
|
||||
displayWidth = t.displayWidthWithLimit(runes, 0, displayWidth)
|
||||
}
|
||||
displayWidthSum += displayWidth
|
||||
|
||||
if maxWidth > 0 {
|
||||
color := colBase
|
||||
if hidden {
|
||||
color = color.WithFg(t.theme.Nomatch)
|
||||
}
|
||||
todo[fidx] = func() {
|
||||
t.printColoredString(t.window, runes, offs, color)
|
||||
}
|
||||
} else {
|
||||
line, _ = t.trimRight(line, maxWidth-ellipsisWidth)
|
||||
line = append(line, ellipsis...)
|
||||
|
||||
for idx, offset := range offsets {
|
||||
offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-len(ellipsis)))
|
||||
offsets[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))
|
||||
}
|
||||
break
|
||||
}
|
||||
displayWidth = t.displayWidthWithLimit(line, 0, displayWidth)
|
||||
maxWidth -= displayWidth
|
||||
}
|
||||
|
||||
if maxWidth > 0 {
|
||||
color := colBase
|
||||
if hidden {
|
||||
color = color.WithFg(t.theme.Nomatch)
|
||||
}
|
||||
t.printColoredString(t.window, line, offsets, color)
|
||||
if todo[0] != nil {
|
||||
todo[0]()
|
||||
}
|
||||
if todo[2] != nil {
|
||||
todo[2]()
|
||||
}
|
||||
if todo[1] != nil {
|
||||
todo[1]()
|
||||
}
|
||||
if postTask != nil {
|
||||
postTask(actualLineNum, displayWidth, wasWrapped, forceRedraw, lbg)
|
||||
postTask(actualLineNum, displayWidthSum, wasWrapped, forceRedraw, lbg)
|
||||
} else {
|
||||
t.markOtherLine(actualLineNum)
|
||||
}
|
||||
@@ -4806,7 +4903,7 @@ func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, [3][]*I
|
||||
if asterisk {
|
||||
cnt := t.merger.Length()
|
||||
all = make([]*Item, cnt)
|
||||
for i := 0; i < cnt; i++ {
|
||||
for i := range cnt {
|
||||
all[i] = t.merger.Get(i).item
|
||||
}
|
||||
}
|
||||
@@ -5523,7 +5620,7 @@ func (t *Terminal) Loop() error {
|
||||
req := func(evts ...util.EventType) {
|
||||
for _, event := range evts {
|
||||
events = append(events, event)
|
||||
if event == reqClose || event == reqQuit {
|
||||
if isTerminalEvent(event) {
|
||||
looping = false
|
||||
}
|
||||
}
|
||||
@@ -7058,7 +7155,7 @@ func (t *Terminal) constrain() {
|
||||
|
||||
// May need to try again after adjusting the offset
|
||||
t.offset = util.Constrain(t.offset, 0, count)
|
||||
for tries := 0; tries < maxLines; tries++ {
|
||||
for range maxLines {
|
||||
numItems := maxLines
|
||||
// How many items can be fit on screen including the current item?
|
||||
if t.canSpanMultiLines() && t.merger.Length() > 0 {
|
||||
@@ -7112,7 +7209,7 @@ func (t *Terminal) constrain() {
|
||||
scrollOff := util.Min(maxLines/2, t.scrollOff)
|
||||
newOffset := t.offset
|
||||
// 2-phase adjustment to avoid infinite loop of alternating between moving up and down
|
||||
for phase := 0; phase < 2; phase++ {
|
||||
for phase := range 2 {
|
||||
for {
|
||||
prevOffset := newOffset
|
||||
numItems := t.merger.Length()
|
||||
|
||||
@@ -206,8 +206,9 @@ func Tokenize(text string, delimiter Delimiter) []Token {
|
||||
if delimiter.regex != nil {
|
||||
locs := delimiter.regex.FindAllStringIndex(text, -1)
|
||||
begin := 0
|
||||
for _, loc := range locs {
|
||||
tokens = append(tokens, text[begin:loc[1]])
|
||||
tokens = make([]string, len(locs))
|
||||
for i, loc := range locs {
|
||||
tokens[i] = text[begin:loc[1]]
|
||||
begin = loc[1]
|
||||
}
|
||||
if begin < len(text) {
|
||||
|
||||
@@ -98,7 +98,7 @@ func (r *LightRenderer) findOffset() (row int, col int) {
|
||||
r.flush()
|
||||
var err error
|
||||
bytes := []byte{}
|
||||
for tries := 0; tries < offsetPollTries; tries++ {
|
||||
for tries := range offsetPollTries {
|
||||
bytes, err = r.getBytesInternal(bytes, tries > 0)
|
||||
if err != nil {
|
||||
return -1, -1
|
||||
|
||||
@@ -371,10 +371,12 @@ func (r *FullscreenRenderer) GetChar() Event {
|
||||
}
|
||||
case rune(tcell.KeyCtrlH):
|
||||
switch {
|
||||
case ctrl:
|
||||
return keyfn('h')
|
||||
case alt:
|
||||
return Event{AltBackspace, 0, nil}
|
||||
case ctrl, none, shift:
|
||||
return keyfn('h')
|
||||
case none, shift:
|
||||
return Event{Backspace, 0, nil}
|
||||
}
|
||||
}
|
||||
case tcell.KeyCtrlI:
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func TestAtExit(t *testing.T) {
|
||||
want := []int{3, 2, 1, 0}
|
||||
var called []int
|
||||
for i := 0; i < 4; i++ {
|
||||
for i := range 4 {
|
||||
n := i
|
||||
AtExit(func() { called = append(called, n) })
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func ToChars(bytes []byte) Chars {
|
||||
}
|
||||
|
||||
runes := make([]rune, bytesUntil, len(bytes))
|
||||
for i := 0; i < bytesUntil; i++ {
|
||||
for i := range bytesUntil {
|
||||
runes[i] = rune(bytes[i])
|
||||
}
|
||||
for i := bytesUntil; i < len(bytes); {
|
||||
@@ -259,7 +259,7 @@ func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWi
|
||||
lines = append(lines, text)
|
||||
} else {
|
||||
from := 0
|
||||
for off := 0; off < len(text); off++ {
|
||||
for off := range text {
|
||||
if text[off] == '\n' {
|
||||
lines = append(lines, text[from:off+1]) // Include '\n'
|
||||
from = off + 1
|
||||
|
||||
@@ -1190,6 +1190,44 @@ class TestCore < TestInteractive
|
||||
tmux.until { |lines| assert lines.any_include?('9999␊10000') }
|
||||
end
|
||||
|
||||
def test_freeze_left_keep_right
|
||||
tmux.send_keys %[seq 10000 | #{FZF} --read0 --delimiter "\n" --freeze-left 3 --keep-right --ellipsis XX --no-multi-line --bind space:toggle-multi-line], :Enter
|
||||
tmux.until { |lines| assert_match(/^> 1␊2␊3XX.*10000␊$/, lines[-3]) }
|
||||
tmux.send_keys '5'
|
||||
tmux.until { |lines| assert_match(/^> 1␊2␊3␊4␊5␊.*XX$/, lines[-3]) }
|
||||
tmux.send_keys :Space
|
||||
tmux.until { |lines| assert lines.any_include?('> 1') }
|
||||
tmux.send_keys :Space
|
||||
tmux.until { |lines| assert lines.any_include?('1␊2␊3␊4␊5␊') }
|
||||
end
|
||||
|
||||
def test_freeze_left_and_right
|
||||
tmux.send_keys %[seq 10000 | tr "\n" ' ' | #{FZF} --freeze-left 3 --freeze-right 3 --ellipsis XX], :Enter
|
||||
tmux.until { |lines| assert_match(/XX9998 9999 10000$/, lines[-3]) }
|
||||
tmux.send_keys "'1000"
|
||||
tmux.until { |lines| assert_match(/^> 1 2 3XX.*XX9998 9999 10000$/,lines[-3]) }
|
||||
end
|
||||
|
||||
def test_freeze_right_exceed_range
|
||||
tmux.send_keys %[seq 10000 | tr "\n" ' ' | #{FZF} --freeze-right 100000 --ellipsis XX], :Enter
|
||||
['', "'1000"].each do |query|
|
||||
tmux.send_keys query
|
||||
tmux.until { |lines| assert lines.any_include?("> #{query}".strip) }
|
||||
tmux.until do |lines|
|
||||
assert_match(/ 9998 9999 10000$/, lines[-3])
|
||||
assert_equal(1, lines[-3].scan('XX').size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_freeze_right_exceed_range_with_freeze_left
|
||||
tmux.send_keys %[seq 10000 | tr "\n" ' ' | #{FZF} --freeze-left 3 --freeze-right 100000 --ellipsis XX], :Enter
|
||||
tmux.until do |lines|
|
||||
assert_match(/^> 1 2 3XX.*9998 9999 10000$/, lines[-3])
|
||||
assert_equal(1, lines[-3].scan('XX').size)
|
||||
end
|
||||
end
|
||||
|
||||
def test_backward_eof
|
||||
tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter
|
||||
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }
|
||||
|
||||
Reference in New Issue
Block a user