From 181d28d85d52b92c4b7a141a31a3a95fed6798d0 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Fri, 14 Feb 2020 22:22:43 +0800 Subject: [PATCH] new: textbox/listbox/preview add a new option: `bordercolor` --- autoload/quickui/listbox.vim | 15 +++++++++++---- autoload/quickui/preview.vim | 20 +++++++++++++++++--- autoload/quickui/style.vim | 2 +- autoload/quickui/textbox.vim | 23 +++++++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/autoload/quickui/listbox.vim b/autoload/quickui/listbox.vim index 1b6d05d..88be7ea 100644 --- a/autoload/quickui/listbox.vim +++ b/autoload/quickui/listbox.vim @@ -3,7 +3,7 @@ " listbox.vim - " " Created by skywind on 2019/12/20 -" Last Modified: 2020/02/13 16:26 +" Last Modified: 2020/02/14 21:06 " "====================================================================== @@ -194,9 +194,11 @@ function! s:vim_create_listbox(textlist, opts) let opts.borderchars = quickui#core#border_vim(border) let opts.border = [1,1,1,1,1,1,1,1,1] endif - let opts.title = has_key(a:opts, 'title')? ' ' . a:opts.title . ' ' : '' + if has_key(a:opts, 'title') && (a:opts.title != '') + let opts.title = ' ' . a:opts.title . ' ' + endif let opts.padding = [0,1,0,1] - if has_key(a:opts, 'close') + if has_key(a:opts, 'close') && (a:opts.close != '') let opts.close = a:opts.close endif let local = quickui#core#popup_local(winid) @@ -217,6 +219,10 @@ function! s:vim_create_listbox(textlist, opts) let hwnd.state = 1 let hwnd.code = 0 let hwnd.tag = '' + if has_key(hwnd.opts, 'bordercolor') + let c = hwnd.opts.bordercolor + let opts.borderhighlight = [c, c, c, c] + endif call popup_setoptions(winid, opts) call win_execute(winid, 'syn clear') if has_key(a:opts, 'syntax') @@ -514,8 +520,9 @@ function! s:nvim_create_listbox(textlist, opts) let op.height = h + 2 let op.row = opts.row - 1 let op.col = opts.col - 1 + let bordercolor = get(a:opts, 'bordercolor', color) let background = nvim_open_win(nbid, 0, op) - call nvim_win_set_option(background, 'winhl', 'Normal:'. color) + call nvim_win_set_option(background, 'winhl', 'Normal:'. bordercolor) endif let hwnd.winid = winid call nvim_win_set_option(winid, 'winhl', 'Normal:'. color) diff --git a/autoload/quickui/preview.vim b/autoload/quickui/preview.vim index ab712d4..4545735 100644 --- a/autoload/quickui/preview.vim +++ b/autoload/quickui/preview.vim @@ -69,7 +69,10 @@ function! quickui#preview#display(content, opts) let source = a:content endif let winid = -1 - let title = has_key(a:opts, 'title')? (' ' . a:opts.title .' ') : '' + let title = '' + if has_key(a:opts, 'title') && (a:opts.title != '') + let title = ' ' . a:opts.title .' ' + endif let w = get(a:opts, 'w', -1) let h = get(a:opts, 'h', -1) let w = (w < 0)? 50 : w @@ -82,7 +85,7 @@ function! quickui#preview#display(content, opts) let winid = popup_create(source, {'wrap':1, 'mapping':0, 'hidden':1}) let opts = {'maxwidth':w, 'maxheight':h, 'minwidth':w, 'minheight':h} call popup_move(winid, opts) - let opts = {'close':'button', 'title':title} + let opts = {'close':'button'} let opts.border = border? [1,1,1,1,1,1,1,1,1] : repeat([0], 9) let opts.resize = 0 let opts.highlight = color @@ -93,8 +96,15 @@ function! quickui#preview#display(content, opts) let opts.drag = 1 let opts.line = p[0] let opts.col = p[1] + if title != '' + let opts.title = title + endif let opts.callback = function('s:popup_exit') " let opts.fixed = 'true' + if has_key(a:opts, 'bordercolor') + let c = a:opts.bordercolor + let opts.borderhighlight = [c, c, c, c] + endif call popup_setoptions(winid, opts) let s:private.winid = winid call popup_show(winid) @@ -126,8 +136,9 @@ function! quickui#preview#display(content, opts) let pos = nvim_win_get_config(winid) let op.row = pos.row - 1 let op.col = pos.col - 1 + let bordercolor = get(a:opts, 'bordercolor', color) let background = nvim_open_win(nbid, 0, op) - call nvim_win_set_option(background, 'winhl', 'Normal:'. color) + call nvim_win_set_option(background, 'winhl', 'Normal:'. bordercolor) let s:private.background = background endif endif @@ -242,6 +253,9 @@ function! quickui#preview#open(content, opts) else let opts.title = 'Preview' .. ((title == '')? '' : (':' .. title)) endif + if g:quickui#style#preview_bordercolor != '' + let opts.bordercolor = g:quickui#style#preview_bordercolor + endif let opts.persist = get(a:opts, 'persist', 0) let opts.focusable = get(g:, 'quickui_preview_focusable', 1) if has_key(a:opts, 'syntax') diff --git a/autoload/quickui/style.vim b/autoload/quickui/style.vim index 661c6bd..36d370d 100644 --- a/autoload/quickui/style.vim +++ b/autoload/quickui/style.vim @@ -17,6 +17,6 @@ let g:quickui#style#tip_head = '[tip]' let g:quickui#style#preview_w = 85 let g:quickui#style#preview_h = 10 let g:quickui#style#preview_number = 1 - +let g:quickui#style#preview_bordercolor = '' diff --git a/autoload/quickui/textbox.vim b/autoload/quickui/textbox.vim index a775eee..fbbaf70 100644 --- a/autoload/quickui/textbox.vim +++ b/autoload/quickui/textbox.vim @@ -3,7 +3,7 @@ " textbox.vim - " " Created by skywind on 2019/12/27 -" Last Modified: 2020/01/02 04:21 +" Last Modified: 2020/02/14 21:06 " "====================================================================== @@ -64,11 +64,16 @@ function! s:vim_create_textbox(textlist, opts) endif let opts = {'mapping':0, 'cursorline':0, 'drag':1} let border = get(a:opts, 'border', 1) - let opts.borderchars = quickui#core#border_vim(border) - let opts.border = [1,1,1,1,1,1,1,1,1] - let opts.title = has_key(a:opts, 'title')? ' ' . a:opts.title . ' ' : '' + let opts.border = [0,0,0,0,0,0,0,0,0] + if border > 0 + let opts.borderchars = quickui#core#border_vim(border) + let opts.border = [1,1,1,1,1,1,1,1,1] + let opts.close = 'button' + endif let opts.padding = [0,1,0,1] - let opts.close = 'button' + if has_key(a:opts, 'title') && (a:opts.title != '') + let opts.title = ' '. a:opts.title . ' ' + endif let opts.filter = function('s:popup_filter') let opts.callback = function('s:popup_exit') let opts.resize = get(a:opts, 'resize', 0) @@ -111,6 +116,10 @@ function! s:vim_create_textbox(textlist, opts) if cursor < 0 call win_execute(winid, 'setlocal nocursorline') endif + if has_key(a:opts, 'bordercolor') + let c = a:opts.bordercolor + let opts.borderhighlight = [c, c, c, c] + endif call popup_setoptions(winid, opts) call win_execute(winid, 'setlocal scrolloff=0') if has_key(a:opts, 'command') @@ -235,8 +244,9 @@ function! s:nvim_create_textbox(textlist, opts) let pos = nvim_win_get_config(winid) let op.row = pos.row - 1 let op.col = pos.col - 1 + let bordercolor = get(a:opts, 'bordercolor', color) let background = nvim_open_win(nbid, 0, op) - call nvim_win_set_option(background, 'winhl', 'Normal:'. color) + call nvim_win_set_option(background, 'winhl', 'Normal:'. bordercolor) endif let init = ['syn clear'] if has_key(a:opts, 'tabstop') @@ -421,6 +431,7 @@ if 0 let opts.title = "title" let opts.syntax = "cpp" let opts.color = "QuickBox" + let opts.border = 0 " let opts.bordercolor = "QuickBG" let opts.cursor = 38 let opts.number = 1