Skip to content
Myr

Provide an option to reverse items only (#1267)

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

authored by Akinori MUSHA · committed by Junegunn Choi · parent 2c26f02 · Browse files · 5 files+136 added−30 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+136 added−30 removed

  • tests:+45 added−2 removed
  • other:+91 added−28 removed

5 files+136 added−30 removed

modified:man/man1/fzf.1+17 added-4 removed
154 unmodified lines
155.BI "--min-height=" "HEIGHT"156Minimum height when \fB--height\fR is given in percent (default: 10).157Ignored when \fB--height\fR is not specified.158.TP159.BI "--layout=" "LAYOUT"160Choose the layout (default: default)161162.br163.BR default " Display from the bottom of the screen"164.br165.BR reverse " Display from the top of the screen"166.br167.BR reverse-list " Display from the top of the screen, prompt at the bottom"168.br169170.TP171.B "--reverse"160Reverse orientation172A synonym for \fB--layout=reverse\fB173174.TP175.B "--border"176Draw border above and below the finder177.TP
29 unmodified lines
207Input prompt (default: '> ')208.TP209.BI "--header=" "STR"210The given string will be printed as the sticky header. The lines are displayed198in the given order from top to bottom regardless of \fB--reverse\fR option, and211in the given order from top to bottom regardless of \fB--layout\fR option, and212are not affected by \fB--with-nth\fR. ANSI color codes are processed even when213\fB--ansi\fR is not set.214.TP215.BI "--header-lines=" "N"
339 unmodified lines
555 \fBselect-all\fR556 \fBtoggle\fR (\fIright-click\fR)557 \fBtoggle-all\fR558 \fBtoggle+down\fR \fIctrl-i (tab)\fR546 \fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)547 \fBtoggle-out\fR (\fB--reverse\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)559 \fBtoggle-in\fR (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)560 \fBtoggle-out\fR (\fB--layout=reverse*\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)561 \fBtoggle-preview\fR562 \fBtoggle-preview-wrap\fR563 \fBtoggle-sort\fR564 \fBtoggle+up\fR \fIbtab (shift-tab)\fR
67 unmodified lines
modified:src/options.go+34 added-6 removed
51 unmodified lines
52 --height=HEIGHT[%] Display fzf window below the cursor with the given53 height instead of using fullscreen54 --min-height=HEIGHT Minimum height when --height is given in percent55 (default: 10)56 --reverse Reverse orientation56 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]57 --border Draw border above and below the finder58 --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)59 --inline-info Display finder info inline with the query60 --prompt=STR Input prompt (default: '> ')
28 unmodified lines
89 --version Display version information and exit9091 Environment variables92 FZF_DEFAULT_COMMAND Default command to use when input is tty93 FZF_DEFAULT_OPTS Default options (e.g. '--reverse --inline-info')93 FZF_DEFAULT_OPTS Default options94 (e.g. '--layout=reverse --inline-info')9596`9798// Case denotes case-sensitivity of search
33 unmodified lines
132 posLeft133 posRight134)135136type layoutType int137138const (139 layoutDefault layoutType = iota140 layoutReverse141 layoutReverseList142)143144type previewOpts struct {145 command string146 position windowPosition147 size sizeSpec
21 unmodified lines
169 Black bool170 Bold bool171 Height sizeSpec172 MinHeight int164 Reverse bool173 Layout layoutType174 Cycle bool175 Hscroll bool176 HscrollOff int177 FileWord bool
41 unmodified lines
219 Theme: tui.EmptyTheme(),220 Black: false,221 Bold: true,222 MinHeight: 10,214 Reverse: false,223 Layout: layoutDefault,224 Cycle: false,225 Hscroll: true,226 HscrollOff: 10,227 FileWord: false,
637 unmodified lines
865 size := parseSize(str, 100, "height")866 return size867}868869func parseLayout(str string) layoutType {870 switch str {871 case "default":872 return layoutDefault873 case "reverse":874 return layoutReverse875 case "reverse-list":876 return layoutReverseList877 default:878 errorExit("invalid layout (expected: default / reverse / reverse-list)")879 }880 return layoutDefault881}882883func parsePreviewWindow(opts *previewOpts, input string) {884 // Default885 opts.position = posRight886 opts.size = sizeSpec{50, true}
172 unmodified lines
1059 case "--bold":1060 opts.Bold = true1061 case "--no-bold":1062 opts.Bold = false1063 case "--layout":1064 opts.Layout = parseLayout(1065 nextString(allArgs, &i, "layout required (default / reverse / reverse-list)"))1066 case "--reverse":1041 opts.Reverse = true1067 opts.Layout = layoutReverse1068 case "--no-reverse":1043 opts.Reverse = false1069 opts.Layout = layoutDefault1070 case "--cycle":1071 opts.Cycle = true1072 case "--no-cycle":1073 opts.Cycle = false
107 unmodified lines
1181 } else if match, value := optString(arg, "--height="); match {1182 opts.Height = parseHeight(value)1183 } else if match, value := optString(arg, "--min-height="); match {1184 opts.MinHeight = atoi(value)1185 } else if match, value := optString(arg, "--layout="); match {1186 opts.Layout = parseLayout(value)1187 } else if match, value := optString(arg, "--toggle-sort="); match {1188 parseToggleSort(opts.Keymap, value)1189 } else if match, value := optString(arg, "--expect="); match {1190 for k, v := range parseKeyChords(value, "key names required") {
113 unmodified lines
modified:src/terminal.go+36 added-14 removed
57 unmodified lines
58 initDelay time.Duration59 inlineInfo bool60 prompt string61 promptLen int62 reverse bool62 layout layoutType63 fullscreen bool64 hscroll bool65 hscrollOff int66 wordRubout string
234 unmodified lines
301// NewTerminal returns new Terminal object302func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {303 input := trimQuery(opts.Query)304 var header []string305 if opts.Reverse {306 header = opts.Header307 } else {305 switch opts.Layout {306 case layoutDefault, layoutReverseList:307 header = reverseStringArray(opts.Header)308 default:309 header = opts.Header310 }311 var delay time.Duration312 if opts.Tac {313 delay = initialDelayTac
49 unmodified lines
363 }364 t := Terminal{365 initDelay: delay,366 inlineInfo: opts.InlineInfo,366 reverse: opts.Reverse,367 layout: opts.Layout,368 fullscreen: fullscreen,369 hscroll: opts.Hscroll,370 hscrollOff: opts.HscrollOff,371 wordRubout: wordRubout,
271 unmodified lines
643 t.truncateQuery()644}645646func (t *Terminal) move(y int, x int, clear bool) {646 if !t.reverse {647 y = t.window.Height() - y - 1647 h := t.window.Height()648649 switch t.layout {650 case layoutDefault:651 y = h - y - 1652 case layoutReverseList:653 n := 2 + len(t.header)654 if t.inlineInfo {655 n--656 }657 if y < n {658 y = h - y - 1659 } else {660 y -= n661 }662 }663664 if clear {665 t.window.MoveAndClear(y, x)
95 unmodified lines
761 maxy := t.maxItems()762 count := t.merger.Length() - t.offset763 for j := 0; j < maxy; j++ {764 i := j751 if !t.reverse {765 if t.layout == layoutDefault {766 i = maxy - 1 - j767 }768 line := i + 2 + len(t.header)769 if t.inlineInfo {
923 unmodified lines
1693 }1694 req(reqList, reqInfo)1695 }1696 case actToggleIn:1683 if t.reverse {1697 if t.layout != layoutDefault {1698 return doAction(action{t: actToggleUp}, mapkey)1699 }1700 return doAction(action{t: actToggleDown}, mapkey)1701 case actToggleOut:1688 if t.reverse {1702 if t.layout != layoutDefault {1703 return doAction(action{t: actToggleDown}, mapkey)1704 }1705 return doAction(action{t: actToggleUp}, mapkey)1706 case actToggleDown:
119 unmodified lines
1826 } else if t.window.Enclose(my, mx) {1827 mx -= t.window.Left()1828 my -= t.window.Top()1829 mx = util.Constrain(mx-t.promptLen, 0, len(t.input))1816 if !t.reverse {1817 my = t.window.Height() - my - 11818 }1830 min := 2 + len(t.header)1831 if t.inlineInfo {1832 min--1833 }1834 h := t.window.Height()1835 switch t.layout {1836 case layoutDefault:1837 my = h - my - 11838 case layoutReverseList:1839 if my < h-min {1840 my += min1841 } else {1842 my = h - my - 11843 }1844 }1845 if me.Double {1846 // Double-click1847 if my >= min {1848 if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
84 unmodified lines
1933 t.offset = util.Max(0, t.offset)1934}19351936func (t *Terminal) vmove(o int, allowCycle bool) {1915 if t.reverse {1937 if t.layout != layoutDefault {1938 o *= -11939 }1940 dest := t.cy + o1941 if t.cycle && allowCycle {
26 unmodified lines
modified:test/test_go.rb+45 added-2 removed
1058 unmodified lines
1059 tmux.send_keys :Enter1060 assert_equal '50', readonce.chomp1061 end10621063 def test_header_lines_reverse_list1064 tmux.send_keys "seq 100 | #{fzf '--header-lines=10 -q 5 --layout=reverse-list'}", :Enter1065 2.times do1066 tmux.until do |lines|1067 lines[0] == '> 50' &&1068 lines[-4] == ' 2' &&1069 lines[-3] == ' 1' &&1070 lines[-2].include?('/90')1071 end1072 tmux.send_keys :Up1073 end1074 tmux.send_keys :Enter1075 assert_equal '50', readonce.chomp1076 end10771078 def test_header_lines_overflow1079 tmux.send_keys "seq 100 | #{fzf '--header-lines=200'}", :Enter1080 tmux.until do |lines|1081 lines[-2].include?('0/0') &&
19 unmodified lines
1101 tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1102 header = File.readlines(FILE).take(5).map(&:strip)1103 tmux.until do |lines|1104 lines[-2].include?('100/100') &&1090 lines[-7..-3].map(&:strip) == header1105 lines[-7..-3].map(&:strip) == header &&1106 lines[-8] == '> 1'1107 end1108 end11091110 def test_header_reverse1111 tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --reverse"}", :Enter1112 header = File.readlines(FILE).take(5).map(&:strip)1113 tmux.until do |lines|1114 lines[1].include?('100/100') &&1099 lines[2..6].map(&:strip) == header1115 lines[2..6].map(&:strip) == header &&1116 lines[7] == '> 1'1117 end1118 end11191120 def test_header_reverse_list1121 tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --layout=reverse-list"}", :Enter1122 header = File.readlines(FILE).take(5).map(&:strip)1123 tmux.until do |lines|1124 lines[-2].include?('100/100') &&1125 lines[-7..-3].map(&:strip) == header &&1126 lines[0] == '> 1'1127 end1128 end11291130 def test_header_and_header_lines1131 tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1132 header = File.readlines(FILE).take(5).map(&:strip)1133 tmux.until do |lines|
12 unmodified lines
1146 lines[7...17].map(&:strip) == (1..10).map(&:to_s)1147 end1148 end11491150 def test_header_and_header_lines_reverse_list1151 tmux.send_keys "seq 100 | #{fzf "--layout=reverse-list --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1152 header = File.readlines(FILE).take(5).map(&:strip)1153 tmux.until do |lines|1154 lines[-2].include?('90/90') &&1155 lines[-7...-2].map(&:strip) == header &&1156 lines[-17...-7].map(&:strip) == (1..10).map(&:to_s).reverse1157 end1158 end11591160 def test_cancel1161 tmux.send_keys "seq 10 | #{fzf '--bind 2:cancel'}", :Enter1162 tmux.until { |lines| lines[-2].include?('10/10') }1163 tmux.send_keys '123'
17 unmodified lines
1181 tmux.until { |lines| lines[1 + 7] == ' 1000/1000' }1182 tmux.send_keys :Enter1183 end11841185 def test_margin_reverse_list1186 tmux.send_keys "yes | head -1000 | #{fzf '--margin 5,3 --layout=reverse-list'}", :Enter1187 tmux.until { |lines| lines[4] == '' && lines[5] == ' > y' }1188 tmux.send_keys :Enter1189 end11901191 def test_tabstop1192 writelines tempname, ["f\too\tba\tr\tbaz\tbarfooq\tux"]1193 {1194 1 => '> f oo ba r baz barfooq ux',
695 unmodified lines
modified:README.md+4 added-4 removed
221 unmodified lines
222```sh223vim $(fzf --height 40%)224```225226Also check out `--reverse` option if you prefer "top-down" layout instead of227the default "bottom-up" layout.226Also check out `--reverse` and `--layout` options if you prefer227"top-down" layout instead of the default "bottom-up" layout.228229```sh230vim $(fzf --height 40% --reverse)231```
1 unmodified line
233You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by234default. For example,235236```sh237export FZF_DEFAULT_OPTS='--height 40% --reverse --border'237export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'238```239240#### Search syntax241
29 unmodified lines
271 - Default command to use when input is tty272 - e.g. `export FZF_DEFAULT_COMMAND='fd --type f'`273- `FZF_DEFAULT_OPTS`274 - Default options275 - e.g. `export FZF_DEFAULT_OPTS="--reverse --inline-info"`275 - e.g. `export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"`276277#### Options278279See the man page (`man fzf`) for the full list of options.
327 unmodified lines