Skip to content
Myr

Add --info=STYLE [default|inline|hidden]

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

Close #1738

authored by Junegunn Choi · committed by Junegunn Choi · parent 168453d · Browse files · 5 files+84 added−29 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+84 added−29 removed

  • tests:+5 added−0 removed
  • other:+79 added−29 removed

5 files+84 added−29 removed

modified:man/man1/fzf.1+15 added-2 removed
210 unmodified lines
211 \fBfzf --margin 10%212 fzf --margin 1,5%\fR213.RE214.TP215.B "--inline-info"216Display finder info inline with the query215.BI "--info=" "STYLE"216Determines the display style of finder info.217218.br219.BR default " Display on the next line to the prompt"220.br221.BR inline " Display on the same line"222.br223.BR hidden " Do not display finder info"224.br225226.TP227.B "--no-info"228A synonym for \fB--info=hidden\fB229230.TP231.BI "--prompt=" "STR"232Input prompt (default: '> ')233.TP234.BI "--header=" "STR"
532 unmodified lines
modified:src/options.go+34 added-5 removed
55 unmodified lines
56 (default: 10)57 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]58 --border Draw border above and below the finder59 --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)60 --inline-info Display finder info inline with the query60 --info=STYLE Finder info style [default|inline|hidden]61 --prompt=STR Input prompt (default: '> ')62 --header=STR String to print as header63 --header-lines=N The first N lines of the input are treated as header64
76 unmodified lines
141 layoutReverse142 layoutReverseList143)144145type infoStyle int146147const (148 infoDefault infoStyle = iota149 infoInline150 infoHidden151)152153type previewOpts struct {154 command string155 position windowPosition156 size sizeSpec
27 unmodified lines
184 Cycle bool185 Hscroll bool186 HscrollOff int187 FileWord bool180 InlineInfo bool188 InfoStyle infoStyle189 JumpLabels string190 Prompt string191 Query string192 Select1 bool
44 unmodified lines
237 Cycle: false,238 Hscroll: true,239 HscrollOff: 10,240 FileWord: false,233 InlineInfo: false,241 InfoStyle: infoDefault,242 JumpLabels: defaultJumpLabels,243 Prompt: "> ",244 Query: "",245 Select1: false,
665 unmodified lines
911 }912 return layoutDefault913}914915func parseInfoStyle(str string) infoStyle {916 switch str {917 case "default":918 return infoDefault919 case "inline":920 return infoInline921 case "hidden":922 return infoHidden923 default:924 errorExit("invalid info style (expected: default / inline / hidden)")925 }926 return infoDefault927}928929func parsePreviewWindow(opts *previewOpts, input string) {930 // Default931 opts.position = posRight932 opts.size = sizeSpec{50, true}
197 unmodified lines
1130 case "--filepath-word":1131 opts.FileWord = true1132 case "--no-filepath-word":1133 opts.FileWord = false1134 case "--info":1135 opts.InfoStyle = parseInfoStyle(1136 nextString(allArgs, &i, "info style required"))1137 case "--no-info":1138 opts.InfoStyle = infoHidden1139 case "--inline-info":1113 opts.InlineInfo = true1140 opts.InfoStyle = infoInline1141 case "--no-inline-info":1115 opts.InlineInfo = false1142 opts.InfoStyle = infoDefault1143 case "--jump-labels":1144 opts.JumpLabels = nextString(allArgs, &i, "label characters required")1145 validateJumpLabels = true1146 case "-1", "--select-1":
99 unmodified lines
1246 } else if match, value := optString(arg, "--min-height="); match {1247 opts.MinHeight = atoi(value)1248 } else if match, value := optString(arg, "--layout="); match {1249 opts.Layout = parseLayout(value)1250 } else if match, value := optString(arg, "--info="); match {1251 opts.InfoStyle = parseInfoStyle(value)1252 } else if match, value := optString(arg, "--toggle-sort="); match {1253 parseToggleSort(opts.Keymap, value)1254 } else if match, value := optString(arg, "--expect="); match {1255 for k, v := range parseKeyChords(value, "key names required") {
113 unmodified lines
modified:src/terminal.go+26 added-22 removed
58 unmodified lines
5960// Terminal represents terminal input/output61type Terminal struct {62 initDelay time.Duration63 inlineInfo bool63 infoStyle infoStyle64 prompt string65 promptLen int66 queryLen [2]int67 layout layoutType
292 unmodified lines
360 effectiveMinHeight := minHeight361 if previewBox != nil && (opts.Preview.position == posUp || opts.Preview.position == posDown) {362 effectiveMinHeight *= 2363 }364 if opts.InlineInfo {364 if opts.InfoStyle != infoDefault {365 effectiveMinHeight -= 1366 }367 if opts.Bordered {368 effectiveMinHeight += 2
10 unmodified lines
379 wordNext = fmt.Sprintf("[^%s]%s|(.$)", sep, sep)380 }381 t := Terminal{382 initDelay: delay,383 inlineInfo: opts.InlineInfo,383 infoStyle: opts.InfoStyle,384 queryLen: [2]int{0, 0},385 layout: opts.Layout,386 fullscreen: fullscreen,387 hscroll: opts.Hscroll,
49 unmodified lines
437 t.prompt, t.promptLen = t.processTabs([]rune(opts.Prompt), 0)438 return &t439}440441func (t *Terminal) noInfoLine() bool {442 return t.infoStyle != infoDefault443}444445// Input returns current query string446func (t *Terminal) Input() []rune {447 t.mutex.Lock()448 defer t.mutex.Unlock()
226 unmodified lines
675 case layoutDefault:676 y = h - y - 1677 case layoutReverseList:678 n := 2 + len(t.header)675 if t.inlineInfo {679 if t.noInfoLine() {680 n--681 }682 if y < n {683 y = h - y - 1
44 unmodified lines
728}729730func (t *Terminal) printInfo() {731 pos := 0728 if t.inlineInfo {732 switch t.infoStyle {733 case infoDefault:734 t.move(1, 0, true)735 if t.reading {736 duration := int64(spinnerDuration)737 idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration738 t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])739 }740 t.move(1, 2, false)741 pos = 2742 case infoInline:743 pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1744 if pos+len(" < ") > t.window.Width() {745 return746 }
3 unmodified lines
750 } else {751 t.window.CPrint(tui.ColPrompt, t.strong, " < ")752 }753 pos += len(" < ")740 } else {741 t.move(1, 0, true)742 if t.reading {743 duration := int64(spinnerDuration)744 idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration745 t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])746 }747 t.move(1, 2, false)748 pos = 2754 case infoHidden:755 return756 }757758 found := t.merger.Length()759 total := util.Max(found, t.count)
33 unmodified lines
793 max := t.window.Height()794 var state *ansiState795 for idx, lineStr := range t.header {796 line := idx + 2790 if t.inlineInfo {797 if t.noInfoLine() {798 line--799 }800 if line >= max {801 continue
20 unmodified lines
822 if t.layout == layoutDefault {823 i = maxy - 1 - j824 }825 line := i + 2 + len(t.header)819 if t.inlineInfo {826 if t.noInfoLine() {827 line--828 }829 if i < count {830 t.printItem(t.merger.Get(i+t.offset), line, i, i == t.cy-t.offset)
765 unmodified lines
1596 }()1597 }15981599 exit := func(getCode func() int) {1593 if !t.cleanExit && t.fullscreen && t.inlineInfo {1594 t.placeCursor()1595 }1600 t.tui.Close()1601 code := getCode()1602 if code <= exitNoMatch && t.history != nil {1603 t.history.append(string(t.input))
12 unmodified lines
1616 for req, value := range *events {1617 switch req {1618 case reqPrompt:1619 t.printPrompt()1616 if t.inlineInfo {1620 if t.noInfoLine() {1621 t.printInfo()1622 }1623 case reqInfo:1624 t.printInfo()
373 unmodified lines
1998 mx -= t.window.Left()1999 my -= t.window.Top()2000 mx = util.Constrain(mx-t.promptLen, 0, len(t.input))2001 min := 2 + len(t.header)1998 if t.inlineInfo {2002 if t.noInfoLine() {2003 min--2004 }2005 h := t.window.Height()2006 switch t.layout {
147 unmodified lines
2154}21552156func (t *Terminal) maxItems() int {2157 max := t.window.Height() - 2 - len(t.header)2154 if t.inlineInfo {2158 if t.noInfoLine() {2159 max++2160 }2161 return util.Max(max, 0)2162}
modified:test/test_go.rb+5 added
1514 unmodified lines
1515 tmux.until { |_| %w[1] == File.readlines(tempname).map(&:chomp) }1516 tmux.until { |lines| lines[-1] == prompt }1517 end15181519 def test_info_hidden1520 tmux.send_keys 'seq 10 | fzf --info=hidden', :Enter1521 tmux.until { |lines| lines[-2] == '> 1' }1522 end15231524 def test_change_top1525 tmux.send_keys %(seq 1000 | #{FZF} --bind change:top), :Enter1526 tmux.until { |lines| lines.match_count == 1000 }1527 tmux.send_keys :Up
489 unmodified lines
modified:CHANGELOG.md+4 added
37 unmodified lines
38 ```sh39 # usage: _fzf_setup_completion path|dir COMMANDS...40 _fzf_setup_completion path git kubectl41 ```42- Info line style can be changed by `--info=STYLE`43 - `--info=default`44 - `--info=inline` (same as old `--inline-info`)45 - `--info=hidden`46- When you transform the input with `--with-nth`, the trailing white spaces47 are removed.48- `ctrl-\`, `ctrl-]`, `ctrl-^`, and `ctrl-/` can now be used with `--bind`49- See https://github.com/junegunn/fzf/milestone/15?closed=1 for more details
714 unmodified lines