Skip to content
Myr

Add --no-input to hide the input section (#4210)

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

Close #2890 Close #1396 You can't type in queries in this mode, and the only way to trigger an fzf search is to use `search(...)` action. # Click header to trigger search fzf --header '[src] [test]' --no-input --layout reverse \ --header-border bottom --input-border \ --bind 'click-header:transform-search:echo ${FZF_CLICK_HEADER_WORD:1:-1}'

authored by Junegunn Choi · committed by GitHub · parent 6b5d461 · Browse files · 9 files+126 added−23 removed
This commit

State

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

Diff stats

9 files+126 added−23 removed

  • tests:+15 added−0 removed
  • other:+111 added−23 removed

9 files+126 added−23 removed

modified:man/man1/fzf.1+5 added
619 unmodified lines
620621.SS INPUT SECTION622623.TP624.B "\-\-no\-input"625Disable and hide the input section. You can no longer type in queries. To626trigger a search, use \fBsearch\fR action.627628.TP629.BI "\-\-prompt=" "STR"630Input prompt (default: '> ')631.TP632.BI "\-\-info=" "STYLE"
1216 unmodified lines
modified:src/tui/dummy.go+1 added
43 unmodified lines
44func (r *FullscreenRenderer) Clear() {}45func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }46func (r *FullscreenRenderer) ShouldEmitResizeEvent() bool { return false }47func (r *FullscreenRenderer) Bell() {}48func (r *FullscreenRenderer) HideCursor() {}49func (r *FullscreenRenderer) Refresh() {}50func (r *FullscreenRenderer) Close() {}51func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }52
10 unmodified lines
modified:src/tui/light.go+17 added-2 removed
75 unmodified lines
76}7778func (r *LightRenderer) flush() {79 if r.queued.Len() > 0 {80 r.flushRaw("\x1b[?7l\x1b[?25l" + r.queued.String() + "\x1b[?25h\x1b[?7h")80 raw := "\x1b[?7l\x1b[?25l" + r.queued.String()81 if r.showCursor {82 raw += "\x1b[?25h\x1b[?7h"83 } else {84 raw += "\x1b[?7h"85 }86 r.flushRaw(raw)87 r.queued.Reset()88 }89}90
24 unmodified lines
115 queued strings.Builder116 y int117 x int118 maxHeightFunc func(int) int119 showCursor bool120121 // Windows only122 ttyinChannel chan byte123 inHandle uintptr
34 unmodified lines
158 yoffset: 0,159 tabstop: tabstop,160 fullscreen: fullscreen,161 upOneLine: false,155 maxHeightFunc: maxHeightFunc}162 maxHeightFunc: maxHeightFunc,163 showCursor: true}164 return &r, nil165}166167func repeat(r rune, times int) string {
598 unmodified lines
766 }767 } else if !r.fullscreen {768 r.csi("u")769 }770 if !r.showCursor {771 r.csi("?25h")772 }773 r.disableMouse()774 r.flush()775 r.closePlatform()776 r.restoreTerminal()
447 unmodified lines
12241225func (w *LightWindow) EraseMaybe() bool {1226 return false1227}12281229func (r *LightRenderer) HideCursor() {1230 r.showCursor = false1231}
modified:src/tui/tcell.go+13 added-2 removed
50 unmodified lines
51 moveCursor bool52 borderStyle BorderStyle53 uri *string54 params *string55 showCursor bool56}5758func (w *TcellWindow) Top() int {59 return w.top
12 unmodified lines
72}7374func (w *TcellWindow) Refresh() {75 if w.moveCursor {76 if w.showCursor {75 _screen.ShowCursor(w.left+w.lastX, w.top+w.lastY)77 _screen.ShowCursor(w.left+w.lastX, w.top+w.lastY)78 }79 w.moveCursor = false80 }81 w.lastX = 082 w.lastY = 0
23 unmodified lines
106func (r *FullscreenRenderer) Bell() {107 _screen.Beep()108}109110func (r *FullscreenRenderer) HideCursor() {111 r.showCursor = false112}113114func (r *FullscreenRenderer) PassThrough(str string) {115 // No-op116 // https://github.com/gdamore/tcell/pull/650#issuecomment-1806442846117}
56 unmodified lines
174 s, e := tcell.NewScreen()175 if e != nil {176 return nil, e177 }178 if !r.showCursor {179 s.HideCursor()180 }181 _screen = s182 }183 return _screen, nil184}
414 unmodified lines
599 left: left,600 width: width,601 height: height,602 normal: normal,593 borderStyle: borderStyle}603 borderStyle: borderStyle,604 showCursor: r.showCursor}605 w.Erase()606 return w607}608
284 unmodified lines
modified:src/tui/tui.go+4 added-1 removed
613 unmodified lines
614 PassThrough(string)615 NeedScrollbarRedraw() bool616 ShouldEmitResizeEvent() bool617 Bell()618 HideCursor()619620 GetChar() Event621622 Top() int
39 unmodified lines
662 mouse bool663 forceBlack bool664 prevDownTime time.Time665 clicks [][2]int666 showCursor bool667}668669func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {670 r := &FullscreenRenderer{671 theme: theme,672 mouse: mouse,673 forceBlack: forceBlack,674 prevDownTime: time.Unix(0, 0),673 clicks: [][2]int{}}675 clicks: [][2]int{},676 showCursor: true}677 return r678}679680var (
393 unmodified lines
modified:src/options.go+15 added-4 removed
125 unmodified lines
126 NEGATIVE_INTEGER: columns from right][:bottom]127 (default: 0 or center)128129 INPUT SECTION130 --no-input Disable and hide the input section131 --prompt=STR Input prompt (default: '> ')132 --info=STYLE Finder info style133 [default|right|hidden|inline[-right][:PREFIX]]134 --info-command=COMMAND Command to generate info line
403 unmodified lines
538 FuzzyAlgo algo.Algo539 Scheme string540 Extended bool541 Phony bool542 Inputless bool543 Case Case544 Normalize bool545 Nth []Range546 WithNth []Range
113 unmodified lines
660 FuzzyAlgo: algo.FuzzyMatchV2,661 Scheme: "", // Unknown662 Extended: true,663 Phony: false,664 Inputless: false,665 Case: CaseSmart,666 Normalize: true,667 Nth: make([]Range, 0),668 WithNth: make([]Range, 0),
1648 unmodified lines
2317 case "--enabled", "--no-phony":2318 opts.Phony = false2319 case "--disabled", "--phony":2320 opts.Phony = true2321 case "--no-input":2322 opts.Inputless = true2323 case "--tiebreak":2324 str, err := nextString("sort criterion required")2325 if err != nil {2326 return err
741 unmodified lines
3068 return false3069}30703071func (opts *Options) noSeparatorLine() bool {3072 if opts.Inputless {3073 return true3074 }3075 sep := opts.Separator == nil && !opts.InputBorderShape.Visible() || opts.Separator != nil && len(*opts.Separator) > 03076 return noSeparatorLine(opts.InfoStyle, sep)3077}3078
163 unmodified lines
3242 }32433244 // Sets --min-height automatically3245 if opts.Height.size > 0 && opts.Height.percent && opts.MinHeight < 0 {3238 opts.MinHeight = -opts.MinHeight + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)3246 opts.MinHeight = -opts.MinHeight + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape)3247 if !opts.Inputless {3248 opts.MinHeight += 1 + borderLines(opts.InputBorderShape)3249 if !opts.noSeparatorLine() {3250 opts.MinHeight++3251 }3252 }3253 if len(opts.Header) > 0 {3254 opts.MinHeight += borderLines(opts.HeaderBorderShape) + len(opts.Header)3255 }3256 if opts.HeaderLines > 0 {
2 unmodified lines
3259 borderShape = opts.HeaderLinesShape3260 }3261 opts.MinHeight += borderLines(borderShape) + opts.HeaderLines3262 }3249 if !opts.noSeparatorLine() {3250 opts.MinHeight++3251 }3263 if len(opts.Preview.command) > 0 && (opts.Preview.position == posUp || opts.Preview.position == posDown) && opts.Preview.Visible() && opts.Preview.position == posUp {3264 borderShape := opts.Preview.border3265 if opts.Preview.border == tui.BorderLine {3266 borderShape = tui.BorderTop
119 unmodified lines
modified:src/terminal.go+49 added-14 removed
322 unmodified lines
323 listLabelOpts labelOpts324 cleanExit bool325 executor *util.Executor326 paused bool327 inputless bool328 border tui.Window329 window tui.Window330 inputWindow tui.Window331 inputBorder tui.Window
478 unmodified lines
810 }811 if err != nil {812 return nil, err813 }814 if opts.Inputless {815 renderer.HideCursor()816 }817 wordRubout := "[^\\pL\\pN][\\pL\\pN]"818 wordNext := "[\\pL\\pN][^\\pL\\pN]|(.$)"819 if opts.FileWord {820 sep := regexp.QuoteMeta(string(os.PathSeparator))
69 unmodified lines
890 headerLabelOpts: opts.HeaderLabel,891 cleanExit: opts.ClearOnExit,892 executor: executor,893 paused: opts.Phony,894 inputless: opts.Inputless,895 cycle: opts.Cycle,896 highlightLine: opts.CursorLine,897 headerVisible: true,898 headerFirst: opts.HeaderFirst,
229 unmodified lines
1128}11291130// Extra number of lines needed to display fzf1131func (t *Terminal) extraLines() int {1127 extra := 11128 if t.inputBorderShape.Visible() {1129 extra += borderLines(t.inputBorderShape)1132 extra := 01133 if !t.inputless {1134 extra++1135 if !t.noSeparatorLine() {1136 extra++1137 }1138 if t.inputBorderShape.Visible() {1139 extra += borderLines(t.inputBorderShape)1140 }1141 }1142 if t.listBorderShape.Visible() {1143 extra += borderLines(t.listBorderShape)1144 }
6 unmodified lines
1151 extra += borderLines(t.headerLinesShape)1152 }1153 extra += t.headerLines1154 }1144 if !t.noSeparatorLine() {1145 extra++1146 }1155 return extra1156}11571158func (t *Terminal) MaxFitAndPad() (int, int) {
113 unmodified lines
1272 return output, promptLen1273}12741275func (t *Terminal) noSeparatorLine() bool {1268 return noSeparatorLine(t.infoStyle, t.separatorLen > 0)1276 return t.inputless || noSeparatorLine(t.infoStyle, t.separatorLen > 0)1277}12781279func getScrollbar(perLine int, total int, height int, offset int) (int, int) {1280 if total == 0 || total*perLine <= height {
76 unmodified lines
1357func (t *Terminal) Input() (bool, []rune) {1358 t.mutex.Lock()1359 defer t.mutex.Unlock()1360 paused := t.paused1361 var src []rune1362 if !t.inputless {1353 src := t.input1363 src = t.input1364 }1365 if t.inputOverride != nil {1366 paused = false1367 src = *t.inputOverride1368 }
276 unmodified lines
1645 }16461647 minAreaWidth := minWidth1648 minAreaHeight := minHeight1649 if t.inputless {1650 minAreaHeight--1651 }1652 if t.noSeparatorLine() {1639 minAreaHeight -= 11653 minAreaHeight--1654 }1655 if t.needPreviewWindow() {1656 minPreviewWidth, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)1657 switch t.activePreviewOpts.position {
111 unmodified lines
1769 shift := 01770 shrink := 01771 hasHeaderWindow := t.hasHeaderWindow()1772 hasHeaderLinesWindow := t.hasHeaderLinesWindow()1759 hasInputWindow := t.inputBorderShape.Visible() || hasHeaderWindow || hasHeaderLinesWindow1773 hasInputWindow := !t.inputless && (t.inputBorderShape.Visible() || hasHeaderWindow || hasHeaderLinesWindow)1774 if hasInputWindow {1775 inputWindowHeight := 21776 if t.noSeparatorLine() {1777 inputWindowHeight--
108 unmodified lines
1886 minPreviewWidth, minPreviewHeight := t.minPreviewSize(previewOpts)1887 switch previewOpts.position {1888 case posUp, posDown:1889 minWindowHeight := minHeight1890 if t.inputless {1891 minWindowHeight--1892 }1893 if t.noSeparatorLine() {1894 minWindowHeight--1895 }1896 pheight := calculateSize(height, previewOpts.size, minWindowHeight, minPreviewHeight)
346 unmodified lines
2243 return 02244}22452246func (t *Terminal) placeCursor() {2247 if t.inputless {2248 return2249 }2250 if t.inputWindow != nil {2251 y := t.inputWindow.Height() - 12252 if t.layout == layoutReverse {2253 y = 0
4 unmodified lines
2258 t.move(t.promptLine(), t.promptLen+t.queryLen[0], false)2259}22602261func (t *Terminal) printPrompt() {2262 if t.inputless {2263 return2264 }2265 w := t.window2266 if t.inputWindow != nil {2267 w = t.inputWindow2268 }
19 unmodified lines
2288 return string(runes) + strings.Repeat(".", util.Constrain(maxWidth, 0, 2))2289}22902291func (t *Terminal) printInfo() {2292 if t.inputless {2293 return2294 }2295 t.withWindow(t.inputWindow, func() { t.printInfoImpl() })2296}22972298func (t *Terminal) printInfoImpl() {
235 unmodified lines
2534}25352536func (t *Terminal) printHeaderImpl(window tui.Window, borderShape tui.BorderShape, lines1 []string, lines2 []string) {2537 max := t.window.Height()2512 if t.inputWindow == nil && window == nil && t.headerFirst {2538 if !t.inputless && t.inputWindow == nil && window == nil && t.headerFirst {2539 max--2540 if !t.noSeparatorLine() {2541 max--2542 }
21 unmodified lines
2564 line := idx2565 if needReverse && idx < len(lines1) {2566 line = len(lines1) - idx - 12567 }2542 if t.inputWindow == nil && window == nil && !t.headerFirst {2568 if !t.inputless && t.inputWindow == nil && window == nil && !t.headerFirst {2569 line++2570 if !t.noSeparatorLine() {2571 line++2572 }
3133 unmodified lines
5706 if clicked && t.headerVisible && t.headerWindow == nil {5707 // Header5708 numLines := t.visibleHeaderLinesInList()5709 lineOffset := 05684 if t.inputWindow == nil && !t.headerFirst {5710 if !t.inputless && t.inputWindow == nil && !t.headerFirst {5711 // offset for info line5712 if t.noSeparatorLine() {5713 lineOffset = 15714 } else {
139 unmodified lines
5854 doAction(&action{t: actChar})5855 } else if !doActions(actions) {5856 continue5857 }5858 if t.inputless {5859 // Always just discard the change5860 t.input = previousInput5861 t.cx = len(t.input)5862 } else {5832 t.truncateQuery()5863 t.truncateQuery()5864 }5865 queryChanged = string(previousInput) != string(t.input)5866 if queryChanged {5867 t.inputOverride = nil5868 }
178 unmodified lines
6047}60486049// Number of prompt lines in the list window6050func (t *Terminal) promptLines() int {6051 if t.inputless {6052 return 06053 }6054 if t.inputWindow != nil {6055 return 06056 }6057 if t.noSeparatorLine() {
77 unmodified lines
modified:test/test_layout.rb+15 added
874 unmodified lines
875 └─────────876 BLOCK877 tmux.until { assert_block(block, _1) }878 end879880 def test_min_height_auto_no_input881 tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --no-input --height 1% --min-height 5+), :Enter882883 block = <<~BLOCK884 ┌─────────885 │ 5886 │ 4887 │ 3888 │ 2889 │ > 1890 └─────────891 BLOCK892 tmux.until { assert_block(block, _1) }893 end894end
modified:CHANGELOG.md+7 added
26 unmodified lines
27 )'28 ```29 - `$FZF_KEY` was updated to expose the type of the click. e.g. `click`, `ctrl-click`, etc. You can use it to implement a more sophisticated behavior.30 - `kill` completion for bash and zsh were updated to use this feature31- Added `--no-input` option to completely disable and hide the input section32 ```sh33 # Click header to trigger search34 fzf --header '[src] [test]' --no-input --layout reverse \35 --header-border bottom --input-border \36 --bind 'click-header:transform-search:echo ${FZF_CLICK_HEADER_WORD:1:-1}'37 ```38- Extended `{q}` placeholder to support ranges. e.g. `{q:1}`, `{q:2..}`, etc.39- Added `search(...)` and `transform-search(...)` action to trigger an fzf search with an arbitrary query string. This can be used to extend the search syntax of fzf. In the following example, fzf will use the first word of the query to trigger ripgrep search, and use the rest of the query to perform fzf search within the result.40 ```sh41 export TEMP=$(mktemp -u)
2469 unmodified lines