Fix --header-lines unaffected by --with-nth

This commit is contained in:
Junegunn Choi 2015-07-22 21:24:02 +09:00
parent 928fccc15b
commit 4e0e03403e
3 changed files with 22 additions and 6 deletions

View File

@ -260,10 +260,14 @@ automatically truncated when the number of the lines exceeds the value.
.TP
.BI "--header-file=" "FILE"
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
.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
.TP
.BI "-q, --query=" "STR"

View File

@ -104,13 +104,13 @@ func Run(opts *Options) {
})
} else {
chunkList = NewChunkList(func(data *string, index int) *Item {
tokens := Tokenize(data, opts.Delimiter)
trans := Transform(tokens, opts.WithNth)
if len(header) < opts.HeaderLines {
header = append(header, *data)
header = append(header, *joinTokens(trans))
eventBox.Set(EvtHeader, header)
return nil
}
tokens := Tokenize(data, opts.Delimiter)
trans := Transform(tokens, opts.WithNth)
item := Item{
text: joinTokens(trans),
origText: data,

View File

@ -688,6 +688,18 @@ class TestGoFZF < TestBase
assert_equal '', readonce.chomp
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
tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__})"}", :Enter
header = File.readlines(__FILE__).take(5).map(&:strip)
@ -698,7 +710,7 @@ class TestGoFZF < TestBase
end
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)
tmux.until do |lines|
lines[1].include?('100/100') &&