Add --border option to draw horizontal lines above and below the finder
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Goes well with --height
authored by Junegunn Choi · committed by Junegunn Choi · parent fe83589 · Browse files · 10 files·+127 added−60 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+127 added−60 removed
- other:+127 added−60 removed
Provenance
- Commit
4b70019- Tree
611efbf- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
fe83589
10 files changed+127 added−60 removed
modified:man/man1/fzf.1+3 added
154 unmodified lines155 .TP156 .B "--reverse"157 Reverse orientation158 .TP159+.B "--border"160+Draw border above and below the finder161+.TP162 .BI "--margin=" MARGIN163 Comma-separated expression for margins around the finder.164 .br165 405 unmodified linesmodified:src/tui/dummy.go+1 added-1 removed
38 unmodified lines39 func (r *FullscreenRenderer) MaxY() int { return 0 }40 41 func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}42 43-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {43+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {44 return nil45 }modified:src/tui/light.go+21 added-9 removed
93 unmodified lines94 95 type LightWindow struct {96 renderer *LightRenderer97 colored bool98- border bool98+ border BorderStyle99 top int100 left int101 width int102 height int496 unmodified lines599 func (r *LightRenderer) IsOptimized() bool {600 return false601 }602 603-func (r *LightRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {603+func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {604 w := &LightWindow{605 renderer: r,606 colored: r.theme != nil,607- border: border,607+ border: borderStyle,608 top: top,609 left: left,610 width: width,611 height: height,1 unmodified line613 bg: colDefault}614 if r.theme != nil {615 w.bg = r.theme.Bg616 }617- if w.border {618- w.drawBorder()617+ w.drawBorder()619- }618 return w619 }620 621 func (w *LightWindow) drawBorder() {622+ switch w.border {623+ case BorderAround:624+ w.drawBorderAround()625+ case BorderHorizontal:626+ w.drawBorderHorizontal()627+ }628+}629+630+func (w *LightWindow) drawBorderHorizontal() {631 w.Move(0, 0)632+ w.CPrint(ColBorder, AttrRegular, repeat("─", w.width))633+ w.Move(w.height-1, 0)634+ w.CPrint(ColBorder, AttrRegular, repeat("─", w.width))635+}636+637+func (w *LightWindow) drawBorderAround() {638+ w.Move(0, 0)639 w.CPrint(ColBorder, AttrRegular, "┌"+repeat("─", w.width-2)+"┐")640 for y := 1; y < w.height-1; y++ {641 w.Move(y, 0)642 w.CPrint(ColBorder, AttrRegular, "│")224 unmodified lines867 }868 }869 870 func (w *LightWindow) Erase() {857- if w.border {858- w.drawBorder()871+ w.drawBorder()859- }872 // We don't erase the window here to avoid flickering during scroll873 w.Move(0, 0)874 }modified:src/tui/ncurses.go+3 added-2 removed
187 unmodified lines188 C.endwin()189 C.delscreen(_screen)190 }191 192-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {192+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {193 win := C.newwin(C.int(height), C.int(width), C.int(top), C.int(left))194 if r.theme != nil {195 C.wbkgd(win, C.chtype(C.COLOR_PAIR(C.int(ColNormal.index()))))196 }197- if border {197+ // FIXME Does not implement BorderHorizontal198+ if borderStyle != BorderNone {199 pair, attr := _colorFn(ColBorder, 0)200 C.wcolor_set(win, pair, nil)201 C.wattron(win, attr)202 C.box(win, 0, 0)304 unmodified linesmodified:src/tui/tcell.go+32 added-27 removed
25 unmodified lines26 27 type Attr tcell.Style28 29 type TcellWindow struct {30- color bool31- top int32- left int33- width int34- height int35- lastX int36- lastY int37- moveCursor bool38- border bool30+ color bool31+ top int32+ left int33+ width int34+ height int35+ lastX int36+ lastY int37+ moveCursor bool38+ borderStyle BorderStyle39 }40 41 func (w *TcellWindow) Top() int {42 return w.top17 unmodified lines60 w.moveCursor = false61 }62 w.lastX = 063 w.lastY = 064- if w.border {65- w.drawBorder()64+ switch w.borderStyle {65+ case BorderAround:66+ w.drawBorder(true)67+ case BorderHorizontal:68+ w.drawBorder(false)69 }70 }71 72 func (w *TcellWindow) FinishFill() {306 unmodified lines379 }380 _screen.Show()381 }382 380-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {383+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {384 // TODO385 return &TcellWindow{383- color: r.theme != nil,384- top: top,385- left: left,386- width: width,387- height: height,388- border: border}386+ color: r.theme != nil,387+ top: top,388+ left: left,389+ width: width,390+ height: height,391+ borderStyle: borderStyle}392 }393 394 func (w *TcellWindow) Close() {395 // TODO142 unmodified lines538 func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {539 return w.fillString(str, ColorPair{fg, bg, -1}, a)540 }541 539-func (w *TcellWindow) drawBorder() {542+func (w *TcellWindow) drawBorder(around bool) {543 left := w.left544 right := left + w.width545 top := w.top546 bot := top + w.height9 unmodified lines556 _screen.SetContent(x, top, tcell.RuneHLine, nil, style)557 _screen.SetContent(x, bot-1, tcell.RuneHLine, nil, style)558 }559 560+ if around {557- for y := top; y < bot; y++ {558- _screen.SetContent(left, y, tcell.RuneVLine, nil, style)559- _screen.SetContent(right-1, y, tcell.RuneVLine, nil, style)560- }561+ for y := top; y < bot; y++ {562+ _screen.SetContent(left, y, tcell.RuneVLine, nil, style)563+ _screen.SetContent(right-1, y, tcell.RuneVLine, nil, style)564+ }565 562- _screen.SetContent(left, top, tcell.RuneULCorner, nil, style)563- _screen.SetContent(right-1, top, tcell.RuneURCorner, nil, style)564- _screen.SetContent(left, bot-1, tcell.RuneLLCorner, nil, style)565- _screen.SetContent(right-1, bot-1, tcell.RuneLRCorner, nil, style)566+ _screen.SetContent(left, top, tcell.RuneULCorner, nil, style)567+ _screen.SetContent(right-1, top, tcell.RuneURCorner, nil, style)568+ _screen.SetContent(left, bot-1, tcell.RuneLLCorner, nil, style)569+ _screen.SetContent(right-1, bot-1, tcell.RuneLRCorner, nil, style)570+ }571 }modified:src/tui/tui.go+9 added-1 removed
193 unmodified lines194 Double bool195 Mod bool196 }197 198+type BorderStyle int199+200+const (201+ BorderNone BorderStyle = iota202+ BorderAround203+ BorderHorizontal204+)205+206 type Renderer interface {207 Init()208 Pause()209 Resume() bool8 unmodified lines218 MaxY() int219 DoesAutoWrap() bool220 IsOptimized() bool221 214- NewWindow(top int, left int, width int, height int, border bool) Window222+ NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window223 }224 225 type Window interface {226 Top() int199 unmodified linesmodified:src/options.go+6 added
52 unmodified lines53 height instead of using fullscreen54 --min-height=HEIGHT Minimum height when --height is given in percent55 (default: 10)56 --reverse Reverse orientation57+ --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: '> ')61 --header=STR String to print as header121 unmodified lines183 History *History184 Header []string185 HeaderLines int186 Margin [4]sizeSpec187+ Bordered bool188 Tabstop int189 Version bool190 }191 895 unmodified lines1087 case "--no-height":1088 opts.Height = sizeSpec{}1089 case "--no-margin":1090 opts.Margin = defaultMargin()1091+ case "--no-border":1092+ opts.Bordered = false1093+ case "--border":1094+ opts.Bordered = true1095 case "--margin":1096 opts.Margin = parseMargin(1097 nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)"))1098 case "--tabstop":136 unmodified linesmodified:src/terminal.go+45 added-18 removed
81 unmodified lines82 ansi bool83 tabstop int84 margin [4]sizeSpec85 strong tui.Attr86+ bordered bool87+ border tui.Window88 window tui.Window87- bwindow tui.Window89+ pborder tui.Window90 pwindow tui.Window91 count int92 progress int93 reading bool202 unmodified lines296 if opts.Height.size > 0 {297 maxHeightFunc := func(termHeight int) int {298 var maxHeight int299 if opts.Height.percent {298- maxHeight = util.Min(termHeight,299- util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight))300+ maxHeight = util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)301 } else {301- maxHeight = util.Min(termHeight, int(opts.Height.size))302+ maxHeight = int(opts.Height.size)303 }304+305+ effectiveMinHeight := minHeight306+ if previewBox != nil && (opts.Preview.position == posUp || opts.Preview.position == posDown) {307+ effectiveMinHeight *= 2308+ }309 if opts.InlineInfo {304- return util.Max(maxHeight, minHeight-1)310+ effectiveMinHeight -= 1311 }306- return util.Max(maxHeight, minHeight)312+ if opts.Bordered {313+ effectiveMinHeight += 2314+ }315+ return util.Min(termHeight, util.Max(maxHeight, effectiveMinHeight))316 }317 renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, maxHeightFunc)318 } else if tui.HasFullscreenRenderer() {319 renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)31 unmodified lines351 pressed: "",352 printQuery: opts.PrintQuery,353 history: opts.History,354 margin: opts.Margin,355+ bordered: opts.Bordered,356 strong: strongAttr,357 cycle: opts.Cycle,358 header: header,359 header0: header,148 unmodified lines508 marginInt[idx] = int(max * sizeSpec.size * 0.01)509 } else {510 marginInt[idx] = int(sizeSpec.size)511 }512+ if t.bordered && idx%2 == 0 {513+ marginInt[idx] += 1514+ }515 }516 adjust := func(idx1 int, idx2 int, max int, min int) {517 if max >= min {518 margin := marginInt[idx1] + marginInt[idx2]17 unmodified lines536 }537 }538 adjust(1, 3, screenWidth, minAreaWidth)539 adjust(0, 2, screenHeight, minAreaHeight)540+ if t.border != nil {541+ t.border.Close()542+ }543 if t.window != nil {544 t.window.Close()545 }530- if t.bwindow != nil {531- t.bwindow.Close()546+ if t.pborder != nil {547+ t.pborder.Close()548 t.pwindow.Close()549 }550 551 width := screenWidth - marginInt[1] - marginInt[3]552 height := screenHeight - marginInt[0] - marginInt[2]553+ if t.bordered {554+ t.border = t.tui.NewWindow(555+ marginInt[0]-1,556+ marginInt[3],557+ width,558+ height+2, tui.BorderHorizontal)559+ }560 if previewVisible {561 createPreviewWindow := func(y int, x int, w int, h int) {539- t.bwindow = t.tui.NewWindow(y, x, w, h, true)562+ t.pborder = t.tui.NewWindow(y, x, w, h, tui.BorderAround)563 pwidth := w - 4564 // ncurses auto-wraps the line when the cursor reaches the right-end of565 // the window. To prevent unintended line-wraps, we use the width one566 // column larger than the desired value.567 if !t.preview.wrap && t.tui.DoesAutoWrap() {568 pwidth += 1569 }547- t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, false)570+ t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)571 }572 switch t.preview.position {573 case posUp:574 pheight := calculateSize(height, t.preview.size, minHeight, 3)575 t.window = t.tui.NewWindow(553- marginInt[0]+pheight, marginInt[3], width, height-pheight, false)576+ marginInt[0]+pheight, marginInt[3], width, height-pheight, tui.BorderNone)577 createPreviewWindow(marginInt[0], marginInt[3], width, pheight)578 case posDown:579 pheight := calculateSize(height, t.preview.size, minHeight, 3)580 t.window = t.tui.NewWindow(558- marginInt[0], marginInt[3], width, height-pheight, false)581+ marginInt[0], marginInt[3], width, height-pheight, tui.BorderNone)582 createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)583 case posLeft:584 pwidth := calculateSize(width, t.preview.size, minWidth, 5)585 t.window = t.tui.NewWindow(563- marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false)586+ marginInt[0], marginInt[3]+pwidth, width-pwidth, height, tui.BorderNone)587 createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)588 case posRight:589 pwidth := calculateSize(width, t.preview.size, minWidth, 5)590 t.window = t.tui.NewWindow(568- marginInt[0], marginInt[3], width-pwidth, height, false)591+ marginInt[0], marginInt[3], width-pwidth, height, tui.BorderNone)592 createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)593 }594 } else {595 t.window = t.tui.NewWindow(596 marginInt[0],597 marginInt[3],598 width,576- height, false)599+ height, tui.BorderNone)600 }601 if !t.tui.IsOptimized() && t.theme != nil && t.theme.HasBg() {602 for i := 0; i < t.window.Height(); i++ {603 t.window.MoveAndClear(i, 0)396 unmodified lines1000 }1001 1002 func (t *Terminal) refresh() {1003 if !t.suppress {1004+ windows := make([]tui.Window, 0, 4)1005+ if t.bordered {1006+ windows = append(windows, t.border)1007+ }1008 if t.hasPreviewWindow() {982- t.tui.RefreshWindows([]tui.Window{t.bwindow, t.pwindow, t.window})983- } else {984- t.tui.RefreshWindows([]tui.Window{t.window})1009+ windows = append(windows, t.pborder, t.pwindow)1010 }1011+ windows = append(windows, t.window)1012+ t.tui.RefreshWindows(windows)1013 }1014 }1015 1016 func (t *Terminal) delChar() bool {750 unmodified linesmodified:CHANGELOG.md+5 added
1 CHANGELOG2 =========3 4+0.16.45+------6+- Added `--border` option to draw border above and below the finder7+- Bug fixes and improvements8+9 0.16.310 ------11 - Fixed a bug where fzf incorrectly display the lines when straddling tab12 characters are trimmed560 unmodified linesmodified:README.md+2 added-2 removed
139 unmodified lines140 vim $(fzf --height 40% --reverse)141 ```142 143 You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by144-default.144+default. For example,145 146 ```sh147-export FZF_DEFAULT_OPTS='--height 40% --reverse'147+export FZF_DEFAULT_OPTS='--height 40% --reverse --border'148 ```149 150 #### Search syntax151 340 unmodified lines