From 2e8e63fb0b3b62e89472eebe9e86578598e1a541 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 26 Oct 2020 22:33:41 +0900 Subject: Add more --border options Instead of drawing the window border in Vim using an extra window, extend the --border option so that we do can it natively. Close #2223 Fix #2184 --- plugin/fzf.vim | 64 +++++++++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) (limited to 'plugin/fzf.vim') diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 83e1cef5..065ac156 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -432,6 +432,7 @@ try elseif use_term let optstr .= ' --no-height' endif + let optstr .= s:border_opt(get(dict, 'window', 0)) let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result if use_term @@ -656,6 +657,27 @@ function! s:getpos() return {'tab': tabpagenr(), 'win': winnr(), 'winid': win_getid(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')} endfunction +function! s:border_opt(window) + if type(a:window) != type({}) + return '' + endif + + " Border style + let style = tolower(get(a:window, 'border', 'rounded')) + if !has_key(a:window, 'border') && !get(a:window, 'rounded', 1) + let style = 'sharp' + endif + + let opt = ' --border=' . style + if has_key(a:window, 'highlight') + let color = s:get_color('fg', a:window.highlight) + if len(color) + let opt .= ' --color=border:' . color + endif + endif + return opt +endfunction + function! s:split(dict) let directions = { \ 'up': ['topleft', 'resize', &lines], @@ -869,12 +891,8 @@ else endif function! s:popup(opts) abort - " Support ambiwidth == 'double' - let ambidouble = &ambiwidth == 'double' ? 2 : 1 - " Size and position let width = min([max([8, a:opts.width > 1 ? a:opts.width : float2nr(&columns * a:opts.width)]), &columns]) - let width += width % ambidouble let height = min([max([4, a:opts.height > 1 ? a:opts.height : float2nr(&lines * a:opts.height)]), &lines - has('nvim')]) let row = float2nr(get(a:opts, 'yoffset', 0.5) * (&lines - height)) let col = float2nr(get(a:opts, 'xoffset', 0.5) * (&columns - width)) @@ -885,45 +903,9 @@ function! s:popup(opts) abort let row += !has('nvim') let col += !has('nvim') - " Border style - 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 =~ '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 = 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 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 + shift.row, 'col': col + shift.col, 'width': width + shift.width, 'height': height + shift.height + \ 'row': row, 'col': col, 'width': width, 'height': height \ }) - if has('nvim') - execute 'autocmd BufWipeout bwipeout '..frame - endif endfunction let s:default_action = { -- cgit v1.2.3 From e73383fbbba172c1375c4b8d09328f30516d5333 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 26 Oct 2020 23:40:58 +0900 Subject: [vim] Add 'none' option for popup border --- plugin/fzf.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugin/fzf.vim') diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 065ac156..671f4537 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -667,6 +667,9 @@ function! s:border_opt(window) if !has_key(a:window, 'border') && !get(a:window, 'rounded', 1) let style = 'sharp' endif + if style == 'none' + return '' + endif let opt = ' --border=' . style if has_key(a:window, 'highlight') -- cgit v1.2.3 From 607081bbaab228f41ebfe1f7aa0e993ab134c205 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 27 Oct 2020 01:01:58 +0900 Subject: [vim] Download latest binary to meet version requirement --- plugin/fzf.vim | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'plugin/fzf.vim') diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 671f4537..1af0597e 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -154,7 +154,20 @@ function! fzf#install() endif endfunction -function! fzf#exec() +function! s:version_requirement(val, min) + let val = split(a:val, '\.') + let min = split(a:min, '\.') + for idx in range(0, len(min) - 1) + let v = get(val, idx, 0) + if v < min[idx] | return 0 + elseif v > min[idx] | return 1 + endif + endfor + return 1 +endfunction + +let s:checked = {} +function! fzf#exec(...) if !exists('s:exec') if executable(s:fzf_go) let s:exec = s:fzf_go @@ -169,6 +182,26 @@ function! fzf#exec() throw 'fzf executable not found' endif endif + + if a:0 && !has_key(s:checked, a:1) + let command = s:exec . ' --version' + let output = systemlist(command) + if v:shell_error || empty(output) + throw printf('Failed to run "%s": %s', command, output) + endif + let fzf_version = matchstr(output[0], '[0-9.]\+') + if s:version_requirement(fzf_version, a:1) + let s:checked[a:1] = 1 + return s:exec + elseif a:0 < 2 && input(printf('You need fzf %s or above. Found: %s. Download binary? (y/n) ', a:1, fzf_version)) =~? '^y' + redraw + call fzf#install() + return fzf#exec(a:1, 1) + else + throw printf('You need to upgrade fzf (required: %s or above)', a:1) + endif + endif + return s:exec endfunction @@ -671,6 +704,8 @@ function! s:border_opt(window) return '' endif + " For --border styles, we need fzf 0.24.0 or above + call fzf#exec('0.24.0') let opt = ' --border=' . style if has_key(a:window, 'highlight') let color = s:get_color('fg', a:window.highlight) -- cgit v1.2.3