Skip to content
Myr

Add --header-first option to display header before prompt line

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #2422

authored by Junegunn Choi · committed by Junegunn Choi · parent ffd8bef · Browse files · 5 files+83 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+83 added−11 removed

  • tests:+33 added−0 removed
  • other:+50 added−11 removed

5 files+83 added−11 removed

modified:man/man1/fzf.1+4 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Nov 2021" "fzf 0.27.4" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Nov 2021" "fzf 0.28.0" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
269 unmodified lines
298.BI "--header-lines=" "N"299The first N lines of the input are treated as the sticky header. When300\fB--with-nth\fR is set, the lines are transformed just like the other301lines that follow.302.TP303.B "--header-first"304Print header before the prompt line305.SS Display306.TP307.B "--ansi"308Enable processing of ANSI color codes
692 unmodified lines
modified:src/options.go+7 added
67 unmodified lines
68 --pointer=STR Pointer to the current line (default: '>')69 --marker=STR Multi-select marker (default: '>')70 --header=STR String to print as header71 --header-lines=N The first N lines of the input are treated as header72 --header-first Print header before the prompt line7374 Display75 --ansi Enable processing of ANSI color codes76 --tabstop=SPACES Number of spaces for a tab character (default: 8)
148 unmodified lines
225 Sync bool226 History *History227 Header []string228 HeaderLines int229 HeaderFirst bool230 Margin [4]sizeSpec231 Padding [4]sizeSpec232 BorderShape tui.BorderShape233 Unicode bool
54 unmodified lines
288 Sync: false,289 History: nil,290 Header: make([]string, 0),291 HeaderLines: 0,292 HeaderFirst: false,293 Margin: defaultMargin(),294 Padding: defaultMargin(),295 Unicode: true,296 Tabstop: 8,
1132 unmodified lines
1429 opts.Header = strLines(nextString(allArgs, &i, "header string required"))1430 case "--header-lines":1431 opts.HeaderLines = atoi(1432 nextString(allArgs, &i, "number of header lines required"))1433 case "--header-first":1434 opts.HeaderFirst = true1435 case "--no-header-first":1436 opts.HeaderFirst = false1437 case "--preview":1438 opts.Preview.command = nextString(allArgs, &i, "preview command required")1439 case "--no-preview":1440 opts.Preview.command = ""
245 unmodified lines
modified:src/terminal.go+34 added-9 removed
138 unmodified lines
139 pressed string140 printQuery bool141 history *History142 cycle bool143 headerFirst bool144 headerLines int145 header []string146 header0 []string147 ansi bool148 tabstop int
381 unmodified lines
530 cleanExit: opts.ClearOnExit,531 paused: opts.Phony,532 strong: strongAttr,533 cycle: opts.Cycle,534 headerFirst: opts.HeaderFirst,535 headerLines: opts.HeaderLines,536 header: header,537 header0: header,538 ansi: opts.Ansi,539 tabstop: opts.Tabstop,
439 unmodified lines
979 t.queryLen = [2]int{beforeLen, afterLen}980 return before, after981}982983func (t *Terminal) promptLine() int {984 if t.headerFirst {985 max := t.window.Height() - 1986 if !t.noInfoLine() {987 max--988 }989 return util.Min(len(t.header0)+t.headerLines, max)990 }991 return 0992}993994func (t *Terminal) placeCursor() {980 t.move(0, t.promptLen+t.queryLen[0], false)995 t.move(t.promptLine(), t.promptLen+t.queryLen[0], false)996}997998func (t *Terminal) printPrompt() {984 t.move(0, 0, true)999 t.move(t.promptLine(), 0, true)1000 t.prompt()10011002 before, after := t.updatePromptOffset()1003 color := tui.ColInput
13 unmodified lines
1017}10181019func (t *Terminal) printInfo() {1020 pos := 01021 line := t.promptLine()1022 switch t.infoStyle {1023 case infoDefault:1008 t.move(1, 0, true)1024 t.move(line+1, 0, true)1025 if t.reading {1026 duration := int64(spinnerDuration)1027 idx := (time.Now().UnixNano() % (duration * int64(len(t.spinner)))) / duration1028 t.window.CPrint(tui.ColSpinner, t.spinner[idx])1029 }1014 t.move(1, 2, false)1030 t.move(line+1, 2, false)1031 pos = 21032 case infoInline:1033 pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 11034 if pos+len(" < ") > t.window.Width() {1035 return1036 }1021 t.move(0, pos, true)1037 t.move(line, pos, true)1038 if t.reading {1039 t.window.CPrint(tui.ColSpinner, " < ")1040 } else {1041 t.window.CPrint(tui.ColPrompt, " < ")
34 unmodified lines
1076 if len(t.header) == 0 {1077 return1078 }1079 max := t.window.Height()1080 if t.headerFirst {1081 max--1082 if !t.noInfoLine() {1083 max--1084 }1085 }1086 var state *ansiState1087 for idx, lineStr := range t.header {1066 line := idx + 21067 if t.noInfoLine() {1068 line--1088 line := idx1089 if !t.headerFirst {1090 line++1091 if !t.noInfoLine() {1092 line++1093 }1094 }1095 if line >= max {1096 continue1097 }
1570 unmodified lines
2668 return doActions(actionsFor(tui.DoubleClick))2669 }2670 }2671 } else if me.Down {2647 if my == 0 && mx >= 0 {2672 if my == t.promptLine() && mx >= 0 {2673 // Prompt2674 t.cx = mx + t.xoffset2675 } else if my >= min {2676 // List
156 unmodified lines
modified:test/test_go.rb+33 added
2107 unmodified lines
2108 tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip }2109 tmux.send_keys :Down2110 tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }2111 end21122113 def test_header_first2114 tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first", :Enter2115 tmux.until do |lines|2116 expected = <<~OUTPUT2117 > 42118 997/9972119 >2120 32121 22122 12123 foobar2124 OUTPUT21252126 assert_equal expected.chomp, lines.reverse.take(7).reverse.join("\n")2127 end2128 end21292130 def test_header_first_reverse2131 tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first --reverse --inline-info", :Enter2132 tmux.until do |lines|2133 expected = <<~OUTPUT2134 foobar2135 12136 22137 32138 > < 997/9972139 > 42140 OUTPUT21412142 assert_equal expected.chomp, lines.take(6).join("\n")2143 end2144 end2145end21462147module TestShell2148 def setup
478 unmodified lines
modified:CHANGELOG.md+5 added-1 removed
1CHANGELOG2=========340.27.440.28.05------6- Added `--header-first` option to print header before the prompt line7 ```sh8 fzf --header $'Welcome to fzf\n▔▔▔▔▔▔▔▔▔▔▔▔▔▔' --reverse --height 30% --border --header-first9 ```10- Added `--scroll-off=LINES` option (similar to `scrolloff` option of Vim)11 - You can set it to a very large number so that the cursor stays in the12 middle of the screen while scrolling13 ```sh
1180 unmodified lines