[vim] Border style for popup window (rounded | sharp | horizontal)

This commit is contained in:
Junegunn Choi 2020-02-06 12:27:48 +09:00
parent 8583b150c9
commit 446df07b62
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 25 additions and 12 deletions

View File

@ -204,7 +204,7 @@ following options are allowed:
- `yoffset` [float default 0.5 range [0 ~ 1]] - `yoffset` [float default 0.5 range [0 ~ 1]]
- `xoffset` [float default 0.5 range [0 ~ 1]] - `xoffset` [float default 0.5 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border - `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded border - `border` [string default `rounded`]: Border style (`rounded` | `sharp` | `horizontal`)
`fzf#wrap` `fzf#wrap`
---------- ----------
@ -300,7 +300,7 @@ The latest versions of Vim and Neovim include builtin terminal emulator
" - xoffset [float default 0.0 range [0 ~ 1]] " - xoffset [float default 0.0 range [0 ~ 1]]
" - yoffset [float default 0.0 range [0 ~ 1]] " - yoffset [float default 0.0 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border " - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border " - border [string default 'rounded']: Border style ('rounded' | 'sharp' | 'horizontal')
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
``` ```

View File

@ -223,7 +223,7 @@ following options are allowed:
- `xoffset` [float default 0.0 range [0 ~ 1]] - `xoffset` [float default 0.0 range [0 ~ 1]]
- `yoffset` [float default 0.0 range [0 ~ 1]] - `yoffset` [float default 0.0 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border - `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded border - `border` [string default `rounded`]: Border style (`rounded` | `sharp` | `horizontal`)
FZF#WRAP FZF#WRAP
@ -315,7 +315,7 @@ Starting fzf in a popup window~
" - xoffset [float default 0.5 range [0 ~ 1]] " - xoffset [float default 0.5 range [0 ~ 1]]
" - yoffset [float default 0.5 range [0 ~ 1]] " - yoffset [float default 0.5 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border " - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border " - border [string default 'rounded']: Border style ('rounded' | 'sharp' | 'horizontal')
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
< <

View File

@ -854,20 +854,33 @@ function! s:popup(opts) abort
let row += !has('nvim') let row += !has('nvim')
let col += !has('nvim') let col += !has('nvim')
" Border " Border style
let edges = get(a:opts, 'rounded', 1) ? ['╭', '╮', '╰', '╯'] : ['┌', '┐', '└', '┘'] let style = get(a:opts, 'border', 'rounded')
if !has_key(a:opts, 'border') && !get(a:opts, 'rounded', 1)
let style = 'sharp'
endif
if style == 'horizontal'
let hor = repeat('─', width)
let mid = repeat(' ', width)
let border = [hor] + repeat([mid], height - 2) + [hor]
let margin = 0
else
let edges = style == 'sharp' ? ['┌', '┐', '└', '┘'] : ['╭', '╮', '╰', '╯']
let bar = repeat('─', width - 2) let bar = repeat('─', width - 2)
let top = edges[0] .. bar .. edges[1] let top = edges[0] .. bar .. edges[1]
let mid = '│' .. repeat(' ', width - 2) .. '│' let mid = '│' .. repeat(' ', width - 2) .. '│'
let bot = edges[2] .. bar .. edges[3] let bot = edges[2] .. bar .. edges[3]
let border = [top] + repeat([mid], height - 2) + [bot] let border = [top] + repeat([mid], height - 2) + [bot]
let margin = 2
endif
let highlight = get(a:opts, 'highlight', 'Comment') let highlight = get(a:opts, 'highlight', 'Comment')
let frame = s:create_popup(highlight, { let frame = s:create_popup(highlight, {
\ 'row': row, 'col': col, 'width': width, 'height': height, 'border': border \ 'row': row, 'col': col, 'width': width, 'height': height, 'border': border
\ }) \ })
call s:create_popup('Normal', { call s:create_popup('Normal', {
\ 'row': row + 1, 'col': col + 2, 'width': width - 4, 'height': height - 2 \ 'row': row + 1, 'col': col + margin, 'width': width - margin * 2, 'height': height - 2
\ }) \ })
if has('nvim') if has('nvim')
execute 'autocmd BufWipeout <buffer> bwipeout '..frame execute 'autocmd BufWipeout <buffer> bwipeout '..frame