Skip to content

Commit

Permalink
[vim] More border styles
Browse files Browse the repository at this point in the history
e.g.

  let g:fzf_layout = { 'window': { 'width': 0.4, 'height': 1, 'xoffset': 0, 'border': 'right' } }
  let g:fzf_layout = { 'window': { 'width': 0.4, 'height': 1, 'xoffset': 1, 'border': 'left' } }
  let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.5, 'yoffset': 1, 'border': 'top' } }
  let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.5, 'yoffset': 0, 'border': 'bottom' } }
  • Loading branch information
junegunn committed Feb 13, 2020
1 parent 5e1db9f commit 4fb410a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions README-VIM.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ following options are allowed:
- `yoffset` [float default 0.5 range [0 ~ 1]]
- `xoffset` [float default 0.5 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border
- `border` [string default `rounded`]: Border style (`rounded` | `sharp` | `horizontal`)
- `border` [string default `rounded`]: Border style
- `rounded` / `sharp` / `horizontal` / `vertical` / `top` / `bottom` / `left` / `right`

`fzf#wrap`
----------
Expand Down Expand Up @@ -300,7 +301,8 @@ The latest versions of Vim and Neovim include builtin terminal emulator
" - xoffset [float default 0.5 range [0 ~ 1]]
" - yoffset [float default 0.5 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border
" - border [string default 'rounded']: Border style ('rounded' | 'sharp' | 'horizontal')
" - border [string default 'rounded']: Border style
" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
```

Expand Down
12 changes: 7 additions & 5 deletions doc/fzf.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fzf.txt fzf Last change: February 6 2020
fzf.txt fzf Last change: February 14 2020
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
==============================================================================

Expand Down Expand Up @@ -220,10 +220,11 @@ following options are allowed:
- `width` [float range [0 ~ 1]]
- `height` [float range [0 ~ 1]]
- Optional:
- `xoffset` [float default 0.0 range [0 ~ 1]]
- `yoffset` [float default 0.0 range [0 ~ 1]]
- `yoffset` [float default 0.5 range [0 ~ 1]]
- `xoffset` [float default 0.5 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border
- `border` [string default `rounded`]: Border style (`rounded` | `sharp` | `horizontal`)
- `border` [string default `rounded`]: Border style
- `rounded` / `sharp` / `horizontal` / `vertical` / `top` / `bottom` / `left` / `right`


FZF#WRAP
Expand Down Expand Up @@ -315,7 +316,8 @@ Starting fzf in a popup window~
" - xoffset [float default 0.5 range [0 ~ 1]]
" - yoffset [float default 0.5 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border
" - border [string default 'rounded']: Border style ('rounded' | 'sharp' | 'horizontal')
" - border [string default 'rounded']: Border style
" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
<

Expand Down
20 changes: 14 additions & 6 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -872,32 +872,40 @@ function! s:popup(opts) abort
let col += !has('nvim')

" Border style
let style = get(a:opts, 'border', 'rounded')
let style = tolower(get(a:opts, 'border', 'rounded'))
if !has_key(a:opts, 'border') && !get(a:opts, 'rounded', 1)
let style = 'sharp'
endif

if style == 'horizontal'
if style =~ 'vertical\|left\|right'
let mid = style == 'vertical' ? '' .. repeat(' ', width - 2 * ambidouble) .. '' :
\ style == 'left' ? '' .. repeat(' ', width - 1 * ambidouble)
\ : repeat(' ', width - 1 * ambidouble) .. ''
let border = repeat([mid], height)
let shift = { 'row': 0, 'col': style == 'right' ? 0 : 2, 'width': style == 'vertical' ? -4 : -2, 'height': 0 }
elseif style =~ 'horizontal\|top\|bottom'
let hor = repeat('', width / ambidouble)
let mid = repeat(' ', width)
let border = [hor] + repeat([mid], height - 2) + [hor]
let margin = 0
let border = style == 'horizontal' ? [hor] + repeat([mid], height - 2) + [hor] :
\ style == 'top' ? [hor] + repeat([mid], height - 1)
\ : repeat([mid], height - 1) + [hor]
let shift = { 'row': style == 'bottom' ? 0 : 1, 'col': 0, 'width': 0, 'height': style == 'horizontal' ? -2 : -1 }
else
let edges = style == 'sharp' ? ['', '', '', ''] : ['', '', '', '']
let bar = repeat('', width / ambidouble - 2)
let top = edges[0] .. bar .. edges[1]
let mid = '' .. repeat(' ', width - 2 * ambidouble) .. ''
let bot = edges[2] .. bar .. edges[3]
let border = [top] + repeat([mid], height - 2) + [bot]
let margin = 2
let shift = { 'row': 1, 'col': 2, 'width': -4, 'height': -2 }
endif

let highlight = get(a:opts, 'highlight', 'Comment')
let frame = s:create_popup(highlight, {
\ 'row': row, 'col': col, 'width': width, 'height': height, 'border': border
\ })
call s:create_popup('Normal', {
\ 'row': row + 1, 'col': col + margin, 'width': width - margin * 2, 'height': height - 2
\ 'row': row + shift.row, 'col': col + shift.col, 'width': width + shift.width, 'height': height + shift.height
\ })
if has('nvim')
execute 'autocmd BufWipeout <buffer> bwipeout '..frame
Expand Down

0 comments on commit 4fb410a

Please sign in to comment.