mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-16 07:13:48 -05:00
Fix --header-lines unaffected by --with-nth
This commit is contained in:
@@ -260,10 +260,14 @@ automatically truncated when the number of the lines exceeds the value.
|
|||||||
.TP
|
.TP
|
||||||
.BI "--header-file=" "FILE"
|
.BI "--header-file=" "FILE"
|
||||||
The content of the file will be printed as the sticky header. The file can
|
The content of the file will be printed as the sticky header. The file can
|
||||||
span multiple lines and can contain ANSI color codes.
|
span multiple lines and can contain ANSI color codes. The lines in the file are
|
||||||
|
displayed from top to bottom regardless of \fB--reverse\fR, and are
|
||||||
|
not affected by \fB--with-nth\fR.
|
||||||
.TP
|
.TP
|
||||||
.BI "--header-lines=" "N"
|
.BI "--header-lines=" "N"
|
||||||
The first N lines of the input are treated as the sticky header.
|
The first N lines of the input are treated as the sticky header. When
|
||||||
|
\fB--with-nth\fR is set, the lines are transformed just like the other
|
||||||
|
lines that follow.
|
||||||
.SS Scripting
|
.SS Scripting
|
||||||
.TP
|
.TP
|
||||||
.BI "-q, --query=" "STR"
|
.BI "-q, --query=" "STR"
|
||||||
|
|||||||
@@ -104,13 +104,13 @@ func Run(opts *Options) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
chunkList = NewChunkList(func(data *string, index int) *Item {
|
chunkList = NewChunkList(func(data *string, index int) *Item {
|
||||||
|
tokens := Tokenize(data, opts.Delimiter)
|
||||||
|
trans := Transform(tokens, opts.WithNth)
|
||||||
if len(header) < opts.HeaderLines {
|
if len(header) < opts.HeaderLines {
|
||||||
header = append(header, *data)
|
header = append(header, *joinTokens(trans))
|
||||||
eventBox.Set(EvtHeader, header)
|
eventBox.Set(EvtHeader, header)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
tokens := Tokenize(data, opts.Delimiter)
|
|
||||||
trans := Transform(tokens, opts.WithNth)
|
|
||||||
item := Item{
|
item := Item{
|
||||||
text: joinTokens(trans),
|
text: joinTokens(trans),
|
||||||
origText: data,
|
origText: data,
|
||||||
|
|||||||
@@ -688,6 +688,18 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal '', readonce.chomp
|
assert_equal '', readonce.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_header_lines_with_nth
|
||||||
|
tmux.send_keys "seq 100 | #{fzf "--header-lines 5 --with-nth 1,1,1,1,1"}", :Enter
|
||||||
|
tmux.until do |lines|
|
||||||
|
lines[-2].include?('95/95') &&
|
||||||
|
lines[-3] == ' 11111' &&
|
||||||
|
lines[-7] == ' 55555' &&
|
||||||
|
lines[-8] == '> 66666'
|
||||||
|
end
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
assert_equal '6', readonce.chomp
|
||||||
|
end
|
||||||
|
|
||||||
def test_header_file
|
def test_header_file
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__})"}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__})"}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
@@ -698,7 +710,7 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_header_file_reverse
|
def test_header_file_reverse
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__}) --reverse"}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header-file=<(head -5 #{__FILE__}) --reverse"}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[1].include?('100/100') &&
|
lines[1].include?('100/100') &&
|
||||||
|
|||||||
Reference in New Issue
Block a user