Implement height range (--height ~[VALUE][%])
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2953
authored by Junegunn Choi · committed by Junegunn Choi · parent 9840495 · Browse files · 11 files·+329 added−67 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+329 added−67 removed
- tests:+87 added−0 removed
- other:+242 added−67 removed
Provenance
- Commit
22cbd9f- Tree
bddf8d5- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
9840495
11 files changed+329 added−67 removed
modified:man/man1/fzf.1+4 added-2 removed
175 unmodified lines176 .BI "--jump-labels=" "CHARS"177 Label characters for \fBjump\fR and \fBjump-accept\fR178 .SS Layout179 .TP180-.BI "--height=" "HEIGHT[%]"180+.BI "--height=" "[~]HEIGHT[%]"181 Display fzf window below the cursor with the given height instead of using182-the full screen.182+the full screen. When prefixed with \fB~\fR, fzf will automatically determine183+the height in the range according to the input size. Note that adaptive height184+is not compatible with top/bottom margin and padding given in percent size.185 .TP186 .BI "--min-height=" "HEIGHT"187 Minimum height when \fB--height\fR is given in percent (default: 10).188 Ignored when \fB--height\fR is not specified.860 unmodified linesmodified:src/tui/dummy.go+7 added-6 removed
25 unmodified lines26 Reverse = Attr(1 << 6)27 StrikeThrough = Attr(1 << 7)28 )29 30-func (r *FullscreenRenderer) Init() {}31-func (r *FullscreenRenderer) Pause(bool) {}32-func (r *FullscreenRenderer) Resume(bool, bool) {}33-func (r *FullscreenRenderer) Clear() {}34-func (r *FullscreenRenderer) Refresh() {}35-func (r *FullscreenRenderer) Close() {}30+func (r *FullscreenRenderer) Init() {}31+func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}32+func (r *FullscreenRenderer) Pause(bool) {}33+func (r *FullscreenRenderer) Resume(bool, bool) {}34+func (r *FullscreenRenderer) Clear() {}35+func (r *FullscreenRenderer) Refresh() {}36+func (r *FullscreenRenderer) Close() {}37 38 func (r *FullscreenRenderer) GetChar() Event { return Event{} }39 func (r *FullscreenRenderer) MaxX() int { return 0 }40 func (r *FullscreenRenderer) MaxY() int { return 0 }6 unmodified linesmodified:src/tui/light.go+7 added
187 unmodified lines188 r.yoffset, _ = r.findOffset()189 }190 }191 192+func (r *LightRenderer) Resize(maxHeightFunc func(int) int) {193+ r.maxHeightFunc = maxHeightFunc194+}195+196 func (r *LightRenderer) makeSpace() {197 r.stderr("\n")198 r.csi("G")199 }479 unmodified lines679 return r.width680 }681 682 func (r *LightRenderer) MaxY() int {683+ if r.height == 0 {684+ r.updateTerminalSize()685+ }686 return r.height687 }688 689 func (r *LightRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {337 unmodified linesmodified:src/tui/tcell.go+2 added
97 unmodified lines98 AttrRegular = Attr(1 << 7)99 AttrClear = Attr(1 << 8)100 )101 102+func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}103+104 func (r *FullscreenRenderer) defaultTheme() *ColorTheme {105 if _screen.Colors() >= 256 {106 return Dark256107 }631 unmodified linesmodified:src/tui/tui.go+1 added
356 unmodified lines357 }358 359 type Renderer interface {360 Init()361+ Resize(maxHeightFunc func(int) int)362 Pause(clear bool)363 Resume(clear bool, sigcont bool)364 Clear()365 RefreshWindows(windows []Window)261 unmodified linesmodified:src/core.go+28 added-7 removed
192 unmodified lines193 go matcher.Loop()194 195 // Terminal I/O196 terminal := NewTerminal(opts, eventBox)197+ maxFit := 0 // Maximum number of items that can fit on screen198+ padHeight := 0199+ heightUnknown := opts.Height.auto200+ if heightUnknown {201+ maxFit, padHeight = terminal.MaxFitAndPad(opts)202+ }203 deferred := opts.Select1 || opts.Exit0204 go terminal.Loop()199- if !deferred {200- terminal.startChan <- true205+ if !deferred && !heightUnknown {206+ // Start right away207+ terminal.startChan <- fitpad{-1, -1}208 }209 210 // Event coordination211 reading := true10 unmodified lines222 header = make([]string, 0, opts.HeaderLines)223 go reader.restart(command)224 }225 eventBox.Watch(EvtReadNew)226+ total := 0227 query := []rune{}228+ determine := func(final bool) {229+ if heightUnknown {230+ if total >= maxFit || final {231+ heightUnknown = false232+ terminal.startChan <- fitpad{util.Min(total, maxFit), padHeight}233+ }234+ } else if deferred {235+ deferred = false236+ terminal.startChan <- fitpad{-1, -1}237+ }238+ }239 for {240 delay := true241 ticks++242 input := func(reloaded bool) []rune {24 unmodified lines267 } else {268 reading = reading && evt == EvtReadNew269 }270 snapshot, count := chunkList.Snapshot()271+ total = count252- terminal.UpdateCount(count, !reading, value.(*string))272+ terminal.UpdateCount(total, !reading, value.(*string))273 if opts.Sync {274 opts.Sync = false275 terminal.UpdateList(PassMerger(&snapshot, opts.Tac), false)276 }277+ if heightUnknown && !deferred {278+ determine(!reading)279+ }280 reset := clearCache()281 matcher.Reset(snapshot, input(reset), false, !reading, sort, reset)282 283 case EvtSearchNew:33 unmodified lines317 case *Merger:318 if deferred {319 count := val.Length()320 if opts.Select1 && count > 1 || opts.Exit0 && !opts.Select1 && count > 0 {298- deferred = false299- terminal.startChan <- true321+ determine(val.final)322 } else if val.final {323 if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {324 if opts.PrintQuery {325 opts.Printer(opts.Query)8 unmodified lines334 os.Exit(exitOk)335 }336 os.Exit(exitNoMatch)337 }316- deferred = false317- terminal.startChan <- true338+ determine(val.final)339 }340 }341 terminal.UpdateList(val, clearSelection())342 }12 unmodified linesmodified:src/options.go+51 added-12 removed
51 unmodified lines52 --filepath-word Make word-wise movements respect path separators53 --jump-labels=CHARS Label characters for jump and jump-accept54 55 Layout56- --height=HEIGHT[%] Display fzf window below the cursor with the given57- height instead of using fullscreen56+ --height=[~]HEIGHT[%] Display fzf window below the cursor with the given57+ height instead of using fullscreen.58+ If prefixed with '~', fzf will determine the height59+ according to the input size.60 --min-height=HEIGHT Minimum height when --height is given in percent61 (default: 10)62 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]63 --border[=STYLE] Draw border around the finder68 unmodified lines132 byBegin133 byEnd134 )135 136+type heightSpec struct {137+ size float64138+ percent bool139+ auto bool140+}141+142 type sizeSpec struct {143 size float64144 percent bool145 }41 unmodified lines187 threshold int188 alternative *previewOpts189 }190 191+func (a previewOpts) aboveOrBelow() bool {192+ return a.size.size > 0 && (a.position == posUp || a.position == posDown)193+}194+195 func (a previewOpts) sameLayout(b previewOpts) bool {196 return a.size == b.size && a.position == b.position && a.border == b.border && a.hidden == b.hidden && a.threshold == b.threshold &&197 (a.alternative != nil && b.alternative != nil && a.alternative.sameLayout(*b.alternative) ||198 a.alternative == nil && b.alternative == nil)23 unmodified lines222 Mouse bool223 Theme *tui.ColorTheme224 Black bool225 Bold bool214- Height sizeSpec226+ Height heightSpec227 MinHeight int228 Layout layoutType229 Cycle bool230 KeepRight bool856 unmodified lines1087 actions = append(actions, &action{t: t, a: actionArg})1088 }1089 if t == actUnbind || t == actRebind {1090 parseKeyChords(actionArg, spec[0:offset]+" target required")1079- } else if t == actChangePreviewWindow {1080- opts := previewOpts{}1081- for _, arg := range strings.Split(actionArg, "|") {1082- parsePreviewWindow(&opts, arg)1083- }1091 }1092 }1093 }1094 prevSpec = ""71 unmodified lines1166 }1167 return sizeSpec{val, percent}1168 }1169 1163-func parseHeight(str string) sizeSpec {1170+func parseHeight(str string) heightSpec {1171+ heightSpec := heightSpec{}1172+ if strings.HasPrefix(str, "~") {1173+ heightSpec.auto = true1174+ str = str[1:]1175+ }1176+1177 size := parseSize(str, 100, "height")1165- return size1178+ heightSpec.size = size.size1179+ heightSpec.percent = size.percent1180+ return heightSpec1181 }1182 1183 func parseLayout(str string) layoutType {1184 switch str {354 unmodified lines1539 case "--preview-window":1540 parsePreviewWindow(&opts.Preview,1541 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][,SIZE[%]][,border-BORDER_OPT][,wrap][,cycle][,hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default]"))1542 case "--height":1528- opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))1543+ opts.Height = parseHeight(nextString(allArgs, &i, "height required: [~]HEIGHT[%]"))1544 case "--min-height":1545 opts.MinHeight = nextInt(allArgs, &i, "height required: HEIGHT")1546 case "--no-height":1532- opts.Height = sizeSpec{}1547+ opts.Height = heightSpec{}1548 case "--no-margin":1549 opts.Margin = defaultMargin()1550 case "--no-padding":1551 opts.Padding = defaultMargin()171 unmodified lines1723 }1724 }1725 1726 // Extend the default key map1727+ previewEnabled := len(opts.Preview.command) > 0 || hasPreviewAction(opts)1728 keymap := defaultKeymap()1729 for key, actions := range opts.Keymap {1730 var lastChangePreviewWindow *action1731 for _, act := range actions {2 unmodified lines1734 // To display "+S"/"-S" on info line1735 opts.ToggleSort = true1736 case actChangePreviewWindow:1737 lastChangePreviewWindow = act1738+ if !previewEnabled {1739+ // Doesn't matter1740+ continue1741+ }1742+ opts := previewOpts{}1743+ for _, arg := range strings.Split(act.a, "|") {1744+ // Make sure that each expression is valid1745+ parsePreviewWindow(&opts, arg)1746+ }1747 }1748 }1749+1750 // Re-organize actions so that we only keep the last change-preview-window1751 // and it comes first in the list.1752 // * change-preview-window(up,+10)+preview(sleep 3; cat {})+change-preview-window(up,+20)1753 // -> change-preview-window(up,+20)+preview(sleep 3; cat {})9 unmodified lines1763 keymap[key] = actions1764 }1765 opts.Keymap = keymap1766 1767+ if opts.Height.auto {1768+ for _, s := range []sizeSpec{opts.Margin[0], opts.Margin[2]} {1769+ if s.percent {1770+ errorExit("adaptive height is not compatible with top/bottom percent margin")1771+ }1772+ }1773+ for _, s := range []sizeSpec{opts.Padding[0], opts.Padding[2]} {1774+ if s.percent {1775+ errorExit("adaptive height is not compatible with top/bottom percent padding")1776+ }1777+ }1778+ }1779+1780 // If we're not using extended search mode, --nth option becomes irrelevant1781 // if it contains the whole range1782 if !opts.Extended || len(opts.Nth) == 1 {1783 for _, r := range opts.Nth {62 unmodified linesmodified:src/terminal.go+111 added-40 removed
98 unmodified lines99 width int100 result Result101 }102 103+type fitpad struct {104+ fit int105+ pad int106+}107+108 var emptyLine = itemLine{}109 110 // Terminal represents terminal input/output111 type Terminal struct {75 unmodified lines187 initFunc func()188 prevLines []itemLine189 suppress bool190 sigstop bool186- startChan chan bool191+ startChan chan fitpad192 killChan chan int193 slab *util.Slab194 theme *tui.ColorTheme195 tui tui.Renderer247 unmodified lines443 }444 return []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}445 }446 447+func evaluateHeight(opts *Options, termHeight int) int {448+ if opts.Height.percent {449+ return util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)450+ }451+ return int(opts.Height.size)452+}453+454 // NewTerminal returns new Terminal object455 func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {456 input := trimQuery(opts.Query)457 var header []string18 unmodified lines476 if !opts.Bold {477 strongAttr = tui.AttrRegular478 }479 var renderer tui.Renderer468- fullscreen := opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100480+ fullscreen := !opts.Height.auto && (opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100)481 if fullscreen {482 if tui.HasFullscreenRenderer() {483 renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)484 } else {1 unmodified line486 true, func(h int) int { return h })487 }488 } else {489 maxHeightFunc := func(termHeight int) int {478- var maxHeight int479- if opts.Height.percent {480- maxHeight = util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)481- } else {482- maxHeight = int(opts.Height.size)483- }484-490+ // Minimum height required to render fzf excluding margin and padding491 effectiveMinHeight := minHeight486- if previewBox != nil && (opts.Preview.position == posUp || opts.Preview.position == posDown) {487- effectiveMinHeight *= 2492+ if previewBox != nil && opts.Preview.aboveOrBelow() {493+ effectiveMinHeight += 1 + borderLines(opts.Preview.border)494 }495 if opts.InfoStyle != infoDefault {496 effectiveMinHeight--497 }492- if opts.BorderShape != tui.BorderNone {493- effectiveMinHeight += 2494- }495- return util.Min(termHeight, util.Max(maxHeight, effectiveMinHeight))498+ effectiveMinHeight += borderLines(opts.BorderShape)499+ return util.Min(termHeight, util.Max(evaluateHeight(opts, termHeight), effectiveMinHeight))500 }501 renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc)502 }503 wordRubout := "[^\\pL\\pN][\\pL\\pN]"71 unmodified lines575 suppress: true,576 sigstop: false,577 slab: util.MakeSlab(slab16Size, slab32Size),578 theme: opts.Theme,575- startChan: make(chan bool, 1),579+ startChan: make(chan fitpad, 1),580 killChan: make(chan int),581 tui: renderer,582 initFunc: func() { renderer.Init() },583 executing: util.NewAtomicBool(false)}6 unmodified lines590 591 return &t592 }593 594+func borderLines(shape tui.BorderShape) int {595+ switch shape {596+ case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp:597+ return 2598+ case tui.BorderTop, tui.BorderBottom:599+ return 1600+ }601+ return 0602+}603+604+// Extra number of lines needed to display fzf605+func (t *Terminal) extraLines() int {606+ extra := len(t.header0) + t.headerLines + 1607+ if !t.noInfoLine() {608+ extra++609+ }610+ return extra611+}612+613+func (t *Terminal) MaxFitAndPad(opts *Options) (int, int) {614+ _, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()615+ padHeight := marginInt[0] + marginInt[2] + paddingInt[0] + paddingInt[2]616+ fit := screenHeight - padHeight - t.extraLines()617+ return fit, padHeight618+}619+620 func (t *Terminal) parsePrompt(prompt string) (func(), int) {621 var state *ansiState622 trimmed, colors, _ := extractColor(prompt, state, nil)623 item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}130 unmodified lines754 }755 756 const (757 minWidth = 4728- minHeight = 4758+ minHeight = 3759 )760 761 func calculateSize(base int, size sizeSpec, occupied int, minSize int, pad int) int {762 max := base - occupied763+ if max < minSize {764+ max = minSize765+ }766 if size.percent {767 return util.Constrain(int(float64(base)*0.01*size.size), minSize, max)768 }769 return util.Constrain(int(size.size)+pad, minSize, max)770 }771 739-func (t *Terminal) resizeWindows() {772+func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) {773 screenWidth := t.tui.MaxX()774 screenHeight := t.tui.MaxY()742- t.prevLines = make([]itemLine, screenHeight)743-775 marginInt := [4]int{} // TRBL776 paddingInt := [4]int{} // TRBL777 sizeSpecToInt := func(index int, spec sizeSpec) int {778 if spec.percent {40 unmodified lines819 marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx]820 }821 822 adjust := func(idx1 int, idx2 int, max int, min int) {792- if max >= min {793- margin := marginInt[idx1] + marginInt[idx2] + paddingInt[idx1] + paddingInt[idx2]794- if max-margin < min {795- desired := max - min796- paddingInt[idx1] = desired * paddingInt[idx1] / margin797- paddingInt[idx2] = desired * paddingInt[idx2] / margin798- marginInt[idx1] = util.Max(extraMargin[idx1], desired*marginInt[idx1]/margin)799- marginInt[idx2] = util.Max(extraMargin[idx2], desired*marginInt[idx2]/margin)800- }823+ if min > max {824+ min = max825 }826+ margin := marginInt[idx1] + marginInt[idx2] + paddingInt[idx1] + paddingInt[idx2]827+ if max-margin < min {828+ desired := max - min829+ paddingInt[idx1] = desired * paddingInt[idx1] / margin830+ paddingInt[idx2] = desired * paddingInt[idx2] / margin831+ marginInt[idx1] = util.Max(extraMargin[idx1], desired*marginInt[idx1]/margin)832+ marginInt[idx2] = util.Max(extraMargin[idx2], desired*marginInt[idx2]/margin)833+ }834 }835 804- previewVisible := t.isPreviewEnabled() && t.previewOpts.size.size > 0836 minAreaWidth := minWidth837 minAreaHeight := minHeight807- if previewVisible {838+ if t.noInfoLine() {839+ minAreaHeight -= 1840+ }841+ if t.isPreviewVisible() {842+ minPreviewHeight := 1 + borderLines(t.previewOpts.border)843+ minPreviewWidth := 5844 switch t.previewOpts.position {845 case posUp, posDown:810- minAreaHeight *= 2846+ minAreaHeight += minPreviewHeight847+ minAreaWidth = util.Max(minPreviewWidth, minAreaWidth)848 case posLeft, posRight:812- minAreaWidth *= 2849+ minAreaWidth += minPreviewWidth850+ minAreaHeight = util.Max(minPreviewHeight, minAreaHeight)851 }852 }853 adjust(1, 3, screenWidth, minAreaWidth)854 adjust(0, 2, screenHeight, minAreaHeight)855+856+ return screenWidth, screenHeight, marginInt, paddingInt857+}858+859+func (t *Terminal) resizeWindows() {860+ screenWidth, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()861+ width := screenWidth - marginInt[1] - marginInt[3]862+ height := screenHeight - marginInt[0] - marginInt[2]863+864+ t.prevLines = make([]itemLine, screenHeight)865 if t.border != nil {866 t.border.Close()867 }868 if t.window != nil {10 unmodified lines879 }880 // Reset preview version so that full redraw occurs881 t.previewed.version = 0882 835- width := screenWidth - marginInt[1] - marginInt[3]836- height := screenHeight - marginInt[0] - marginInt[2]883 switch t.borderShape {884 case tui.BorderHorizontal:885 t.border = t.tui.NewWindow(886 marginInt[0]-1, marginInt[3], width, height+2,23 unmodified lines910 marginInt[0]-1, marginInt[3]-2, width+4, height+2,911 false, tui.MakeBorderStyle(t.borderShape, t.unicode))912 }913 868- // Add padding914+ // Add padding to margin915 for idx, val := range paddingInt {916 marginInt[idx] += val917 }872- width = screenWidth - marginInt[1] - marginInt[3]873- height = screenHeight - marginInt[0] - marginInt[2]918+ width -= paddingInt[1] + paddingInt[3]919+ height -= paddingInt[0] + paddingInt[2]920 921 // Set up preview window922 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)877- if previewVisible {923+ if t.isPreviewVisible() {924 var resizePreviewWindows func(previewOpts previewOpts)925 resizePreviewWindows = func(previewOpts previewOpts) {926 hasThreshold := previewOpts.threshold > 0 && previewOpts.alternative != nil927 createPreviewWindow := func(y int, x int, w int, h int) {980 unmodified lines1908 func (t *Terminal) isPreviewEnabled() bool {1909 return t.hasPreviewer() && t.previewer.enabled1910 }1911 1912+func (t *Terminal) isPreviewVisible() bool {1913+ return t.isPreviewEnabled() && t.previewOpts.size.size > 01914+}1915+1916 func (t *Terminal) hasPreviewWindow() bool {1917 return t.pwindow != nil && t.isPreviewEnabled()1918 }1919 91 unmodified lines2011 2012 // Loop is called to start Terminal I/O2013 func (t *Terminal) Loop() {2014 // prof := profile.Start(profile.ProfilePath("/tmp/"))1965- <-t.startChan2015+ fitpad := <-t.startChan2016+ fit := fitpad.fit2017+ if fit >= 0 {2018+ pad := fitpad.pad2019+ t.tui.Resize(func(termHeight int) int {2020+ contentHeight := fit + t.extraLines()2021+ if t.hasPreviewer() {2022+ if t.previewOpts.aboveOrBelow() {2023+ if t.previewOpts.size.percent {2024+ newContentHeight := int(float64(contentHeight) * 100. / (100. - t.previewOpts.size.size))2025+ contentHeight = util.Max(contentHeight+1+borderLines(t.previewOpts.border), newContentHeight)2026+ } else {2027+ contentHeight += int(t.previewOpts.size.size) + borderLines(t.previewOpts.border)2028+ }2029+ } else {2030+ // Minimum height if preview window can appear2031+ contentHeight = util.Max(contentHeight, 1+borderLines(t.previewOpts.border))2032+ }2033+ }2034+ return util.Min(termHeight, contentHeight+pad)2035+ })2036+ }2037 { // Late initialization2038 intChan := make(chan os.Signal, 1)2039 signal.Notify(intChan, os.Interrupt, syscall.SIGTERM)2040 go func() {968 unmodified linesmodified:test/test_go.rb+87 added
2243 unmodified lines2244 tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter2245 tmux.until { |lines| assert_equal 1, lines.match_count }2246 tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }2247 end2248+2249+ def assert_block(expected, lines)2250+ cols = expected.lines.map(&:chomp).map(&:length).max2251+ actual = lines.reverse.take(expected.lines.length).reverse.map { _1[0, cols].rstrip + "\n" }.join2252+ assert_equal expected, actual2253+ end2254+2255+ def test_height_range_fit2256+ tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border', :Enter2257+ expected = <<~OUTPUT2258+ ╭──────────2259+ │ 32260+ │ 22261+ │ > 12262+ │ > < 3/32263+ ╰──────────2264+ OUTPUT2265+ tmux.until { assert_block(expected, _1) }2266+ end2267+2268+ def test_height_range_fit_preview_above2269+ tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border --preview "seq {}" --preview-window up,60%', :Enter2270+ expected = <<~OUTPUT2271+ ╭──────────2272+ │ ╭────────2273+ │ │ 12274+ │ │2275+ │ │2276+ │ │2277+ │ ╰────────2278+ │ 32279+ │ 22280+ │ > 12281+ │ > < 3/32282+ ╰──────────2283+ OUTPUT2284+ tmux.until { assert_block(expected, _1) }2285+ end2286+2287+ def test_height_range_fit_preview_above_alternative2288+ tmux.send_keys 'seq 3 | fzf --height ~100% --border=sharp --preview "seq {}" --preview-window up,40%,border-bottom --padding 1 --exit-0 --header hello --header-lines=2', :Enter2289+ expected = <<~OUTPUT2290+ ┌─────────2291+ │2292+ │ 12293+ │ 22294+ │ 32295+ │ ───────2296+ │ > 32297+ │ 22298+ │ 12299+ │ hello2300+ │ 1/12301+ │ >2302+ │2303+ └─────────2304+ OUTPUT2305+ tmux.until { assert_block(expected, _1) }2306+ end2307+2308+ def test_height_range_fit_preview_left2309+ tmux.send_keys "seq 3 | fzf --height ~100% --border=vertical --preview 'seq {}' --preview-window left,5,border-right --padding 1 --exit-0 --header $'hello\\nworld' --header-lines=2", :Enter2310+ expected = <<~OUTPUT2311+ │2312+ │ 1 │> 32313+ │ 2 │ 22314+ │ 3 │ 12315+ │ │ hello2316+ │ │ world2317+ │ │ 1/12318+ │ │>2319+ │2320+ OUTPUT2321+ tmux.until { assert_block(expected, _1) }2322+ end2323+2324+ def test_height_range_overflow2325+ tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border', :Enter2326+ expected = <<~OUTPUT2327+ ╭──────────────2328+ │ 22329+ │ > 12330+ │ > < 100/1002331+ ╰──────────────2332+ OUTPUT2333+ tmux.until { assert_block(expected, _1) }2334+ end2335 end2336 2337 module TestShell2338 def setup478 unmodified linesmodified:CHANGELOG.md+30 added
1 CHANGELOG2 =========3 4+0.34.05+------6+- Added support for adaptive `--height`. If the `--height` value is prefixed7+ with `~`, fzf will automatically determine the height in the range according8+ to the input size.9+ ```sh10+ seq 1 | fzf --height ~70% --border --padding 1 --margin 111+ seq 10 | fzf --height ~70% --border --padding 1 --margin 112+ seq 100 | fzf --height ~70% --border --padding 1 --margin 113+ ```14+ - There are a few limitations15+ - Not compatible with percent top/bottom margin/padding16+ ```sh17+ # This is not allowed (top/bottom margin in percent value)18+ fzf --height ~50% --border --margin 5%,10%19+20+ # This is allowed (top/bottom margin in fixed value)21+ fzf --height ~50% --border --margin 2,10%22+ ```23+ - fzf will not start until it can determine the right height for the input24+ ```sh25+ # fzf will open immediately26+ (sleep 2; seq 10) | fzf --height 50%27+28+ # fzf will open after 2 seconds29+ (sleep 2; seq 10) | fzf --height ~50%30+ (sleep 2; seq 1000) | fzf --height ~50%31+ ```32+- Fixed tcell renderer used to render full-screen fzf on Windows33+34 0.33.035 ------36 - Added `--scheme=[default|path|history]` option to choose scoring scheme37 - (Experimental)1307 unmodified linesmodified:Makefile+1 added
153 unmodified lines154 target/$(BINARYLOONG64): $(SOURCES)155 GOARCH=loong64 $(GO) build $(BUILD_FLAGS) -o $@156 157 bin/fzf: target/$(BINARY) | bin158+ -rm -f bin/fzf159 cp -f target/$(BINARY) bin/fzf160 161 docker:162 docker build -t fzf-arch .11 unmodified lines