From 64b2199683d112ae4ea237f423305ba632a1b0ca Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Mon, 24 Feb 2020 18:18:53 +0800 Subject: [PATCH] Add float terminal windows support (#3377) --- autoload/SpaceVim/layers/shell.vim | 26 ++++++++++++++++++++------ docs/cn/layers/shell.md | 2 +- docs/layers/shell.md | 5 +++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/autoload/SpaceVim/layers/shell.vim b/autoload/SpaceVim/layers/shell.vim index 6103c25f4..448391cc1 100644 --- a/autoload/SpaceVim/layers/shell.vim +++ b/autoload/SpaceVim/layers/shell.vim @@ -23,6 +23,7 @@ " < let s:SYSTEM = SpaceVim#api#import('system') +let s:FLOAT = SpaceVim#api#import('neovim#floating') function! SpaceVim#layers#shell#plugins() abort let plugins = [] @@ -122,7 +123,7 @@ endfunction function! SpaceVim#layers#shell#get_options() abort - return ['default_shell', 'default_position', 'default_height'] + return ['default_shell', 'default_position', 'default_height',] endfunction @@ -169,12 +170,25 @@ function! s:open_default_shell(open_with_file_cwd) abort \ 'botright split' : \ s:default_position ==# 'right' ? \ 'rightbelow vsplit' : 'leftabove vsplit' - exe cmd - let w:shell_layer_win = 1 - let lines = &lines * s:default_height / 100 - if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom') - exe 'resize ' . lines + if s:default_position == 'float' + let s:term_win_id = s:FLOAT.open_win(bufnr('%'), v:true, + \ { + \ 'relative': 'editor', + \ 'width' : &columns, + \ 'height' : &lines * s:default_height / 100, + \ 'row': 0, + \ 'col': &lines - (&lines * s:default_height / 100) - 2 + \ }) + + exe win_id2win(s:term_win_id) . 'wincmd w' + else + exe cmd + let lines = &lines * s:default_height / 100 + if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom') + exe 'resize ' . lines + endif endif + let w:shell_layer_win = 1 for open_terminal in s:open_terminals_buffers if bufexists(open_terminal) if getbufvar(open_terminal, '_spacevim_shell_cwd') ==# l:path diff --git a/docs/cn/layers/shell.md b/docs/cn/layers/shell.md index 05762cedc..192bbd7ba 100644 --- a/docs/cn/layers/shell.md +++ b/docs/cn/layers/shell.md @@ -44,7 +44,7 @@ The default shell is quickly accessible via a the default shortcut key `SPC '`. ### 设置终端打开位置及高度 在启用该模块时,可以通过 `default_position` 这一模块选项来指定终端打开的位置, -目前可以选的值为:`top`, `bottom`, `left`, `right`, or `full`,默认的值为 `top`。 +目前可以选的值为:`top`, `bottom`, `left`, `right`, `float` or `full`,默认的值为 `top`。 同时,可以通过 `default_height` 这一模块选项指定终端打开的高度,默认值为 30。 diff --git a/docs/layers/shell.md b/docs/layers/shell.md index 5e3e2f294..1ed212a4e 100644 --- a/docs/layers/shell.md +++ b/docs/layers/shell.md @@ -13,6 +13,7 @@ description: "This layer provide shell support in SpaceVim" - [Default shell](#default-shell) - [Default shell position and height](#default-shell-position-and-height) - [Key bindings](#key-bindings) + - [Additional key bindings on Windows](#additional-key-bindings-on-windows) @@ -45,8 +46,8 @@ The default shell is quickly accessible via a the default shortcut key `SPC '`. ### Default shell position and height It is possible to choose where the shell should pop up by setting the -variable `default_position` to either `top`, `bottom`, `left`, `right`, or -`full`. Default value is `top`. It is also possible to set the default height +variable `default_position` to either `top`, `bottom`, `left`, `right`, `float` +or `full`. Default value is `top`. It is also possible to set the default height in percents with the variable `default_height`. Default value is 30. ```toml