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
Provenance
- Commit
6c0ca4a- Tree
b3cb6ee- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
6b5d461
9 files changed+126 added−23 removed
modified:man/man1/fzf.1+5 added
619 unmodified lines620 621 .SS INPUT SECTION622 623 .TP624+.B "\-\-no\-input"625+Disable and hide the input section. You can no longer type in queries. To626+trigger a search, use \fBsearch\fR action.627+628+.TP629 .BI "\-\-prompt=" "STR"630 Input prompt (default: '> ')631 .TP632 .BI "\-\-info=" "STYLE"1216 unmodified linesmodified:src/tui/dummy.go+1 added
43 unmodified lines44 func (r *FullscreenRenderer) Clear() {}45 func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }46 func (r *FullscreenRenderer) ShouldEmitResizeEvent() bool { return false }47 func (r *FullscreenRenderer) Bell() {}48+func (r *FullscreenRenderer) HideCursor() {}49 func (r *FullscreenRenderer) Refresh() {}50 func (r *FullscreenRenderer) Close() {}51 func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }52 10 unmodified linesmodified:src/tui/light.go+17 added-2 removed
75 unmodified lines76 }77 78 func (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 lines115 queued strings.Builder116 y int117 x int118 maxHeightFunc func(int) int119+ showCursor bool120 121 // Windows only122 ttyinChannel chan byte123 inHandle uintptr34 unmodified lines158 yoffset: 0,159 tabstop: tabstop,160 fullscreen: fullscreen,161 upOneLine: false,155- maxHeightFunc: maxHeightFunc}162+ maxHeightFunc: maxHeightFunc,163+ showCursor: true}164 return &r, nil165 }166 167 func repeat(r rune, times int) string {598 unmodified lines766 }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 lines1224 1225 func (w *LightWindow) EraseMaybe() bool {1226 return false1227 }1228+1229+func (r *LightRenderer) HideCursor() {1230+ r.showCursor = false1231+}modified:src/tui/tcell.go+13 added-2 removed
50 unmodified lines51 moveCursor bool52 borderStyle BorderStyle53 uri *string54 params *string55+ showCursor bool56 }57 58 func (w *TcellWindow) Top() int {59 return w.top12 unmodified lines72 }73 74 func (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 = 023 unmodified lines106 func (r *FullscreenRenderer) Bell() {107 _screen.Beep()108 }109 110+func (r *FullscreenRenderer) HideCursor() {111+ r.showCursor = false112+}113+114 func (r *FullscreenRenderer) PassThrough(str string) {115 // No-op116 // https://github.com/gdamore/tcell/pull/650#issuecomment-1806442846117 }56 unmodified lines174 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 lines599 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 linesmodified:src/tui/tui.go+4 added-1 removed
613 unmodified lines614 PassThrough(string)615 NeedScrollbarRedraw() bool616 ShouldEmitResizeEvent() bool617 Bell()618+ HideCursor()619 620 GetChar() Event621 622 Top() int39 unmodified lines662 mouse bool663 forceBlack bool664 prevDownTime time.Time665 clicks [][2]int666+ showCursor bool667 }668 669 func 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 }679 680 var (393 unmodified linesmodified:src/options.go+15 added-4 removed
125 unmodified lines126 NEGATIVE_INTEGER: columns from right][:bottom]127 (default: 0 or center)128 129 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 line403 unmodified lines538 FuzzyAlgo algo.Algo539 Scheme string540 Extended bool541 Phony bool542+ Inputless bool543 Case Case544 Normalize bool545 Nth []Range546 WithNth []Range113 unmodified lines660 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 lines2317 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 err741 unmodified lines3068 return false3069 }3070 3071 func (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 lines3242 }3243 3244 // 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 lines3259 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.BorderTop119 unmodified linesmodified:src/terminal.go+49 added-14 removed
322 unmodified lines323 listLabelOpts labelOpts324 cleanExit bool325 executor *util.Executor326 paused bool327+ inputless bool328 border tui.Window329 window tui.Window330 inputWindow tui.Window331 inputBorder tui.Window478 unmodified lines810 }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 lines890 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 lines1128 }1129 1130 // Extra number of lines needed to display fzf1131 func (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 lines1151 extra += borderLines(t.headerLinesShape)1152 }1153 extra += t.headerLines1154 }1144- if !t.noSeparatorLine() {1145- extra++1146- }1155 return extra1156 }1157 1158 func (t *Terminal) MaxFitAndPad() (int, int) {113 unmodified lines1272 return output, promptLen1273 }1274 1275 func (t *Terminal) noSeparatorLine() bool {1268- return noSeparatorLine(t.infoStyle, t.separatorLen > 0)1276+ return t.inputless || noSeparatorLine(t.infoStyle, t.separatorLen > 0)1277 }1278 1279 func getScrollbar(perLine int, total int, height int, offset int) (int, int) {1280 if total == 0 || total*perLine <= height {76 unmodified lines1357 func (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 lines1645 }1646 1647 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 lines1769 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 lines1886 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 lines2243 return 02244 }2245 2246 func (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 = 04 unmodified lines2258 t.move(t.promptLine(), t.promptLen+t.queryLen[0], false)2259 }2260 2261 func (t *Terminal) printPrompt() {2262+ if t.inputless {2263+ return2264+ }2265 w := t.window2266 if t.inputWindow != nil {2267 w = t.inputWindow2268 }19 unmodified lines2288 return string(runes) + strings.Repeat(".", util.Constrain(maxWidth, 0, 2))2289 }2290 2291 func (t *Terminal) printInfo() {2292+ if t.inputless {2293+ return2294+ }2295 t.withWindow(t.inputWindow, func() { t.printInfoImpl() })2296 }2297 2298 func (t *Terminal) printInfoImpl() {235 unmodified lines2534 }2535 2536 func (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 lines2564 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 lines5706 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 lines5854 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 lines6047 }6048 6049 // Number of prompt lines in the list window6050 func (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 linesmodified:test/test_layout.rb+15 added
874 unmodified lines875 └─────────876 BLOCK877 tmux.until { assert_block(block, _1) }878 end879+880+ def test_min_height_auto_no_input881+ tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --no-input --height 1% --min-height 5+), :Enter882+883+ block = <<~BLOCK884+ ┌─────────885+ │ 5886+ │ 4887+ │ 3888+ │ 2889+ │ > 1890+ └─────────891+ BLOCK892+ tmux.until { assert_block(block, _1) }893+ end894 endmodified:CHANGELOG.md+7 added
26 unmodified lines27 )'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