Skip to content

Commit

Permalink
feat(output): configure size of win
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop 0.4.4 support

See #103
  • Loading branch information
rcarriga committed Feb 19, 2022
1 parent 0aa467d commit 971655d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ Due to the differences between Vim and NeoVim and their RPC libraries, it is ine
I primarily use NeoVim so I will catch issues in it myself.
Please file bug reports for Vim if you find them!

NeoVim >= 0.4.4 is supported for now, but only >= 0.5 will be supported in future due to added complexity from handling missing features.
Please update your NeoVim version if you have not already.
NeoVim >= 0.5 is currently supported.

vim-ultest can be installed as usual with your favourite plugin manager.
**Note:** NeoVim users must run `:UpdateRemotePlugins` after install if they don't use a plugin manager that already does.
Expand Down
43 changes: 9 additions & 34 deletions autoload/ultest/output.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
let s:height_buffer = has("nvim") ? 2 : 0
let s:width_buffer = has("nvim") ? 4 : 0

augroup UltestOutputClose
autocmd!
autocmd User UltestOutputOpen call ultest#output#close(v:false)
Expand All @@ -20,11 +17,7 @@ function! ultest#output#open(test) abort
if output == "" | return | endif
let [width, height] = s:CalculateBounds(output)
if has("nvim")
if exists("*nvim_open_term")
let cmd = output
else
let cmd = ['less', "-R", "-Ps", shellescape(output)]
endif
let cmd = output
call s:NvimOpenFloat(cmd, width, height, "UltestOutput")
autocmd InsertEnter,CursorMoved * ++once call ultest#output#close(v:false)
else
Expand Down Expand Up @@ -96,8 +89,8 @@ function! s:CalculateBounds(path) abort
let width = str2nr(split(system("sed 's/\x1b\[[0-9;]*m//g' ".shellescape(a:path)." | wc -L"))[0])
let height = str2nr(split(system("wc -l ".shellescape(a:path)))[0])

let height = min([max([height + s:height_buffer, 20]), &lines - s:height_buffer])
let width = min([max([width + s:width_buffer, 80]), &columns - s:width_buffer])
let height = min([max([height, g:ultest_output_min_height]), &lines, g:ultest_output_max_height ? g:ultest_output_max_height : 10000])
let width = min([max([width, g:ultest_output_min_height]), &columns, g:ultest_output_max_width ? g:ultest_output_max_width : 10000])
return [width, height]
endfunction

Expand Down Expand Up @@ -129,46 +122,28 @@ function! s:NvimOpenFloat(cmd, width, height, filetype) abort
let row = min([1, &lines - (lineNo + a:height)])
let col = min([1, &columns - (colNo + a:width)])

let border_opts = {
let content_opts = {
\ 'relative': 'cursor',
\ 'row': row,
\ 'col': col,
\ 'anchor': vert_anchor.hor_anchor,
\ 'width': a:width,
\ 'height': a:height,
\ 'style': 'minimal'
\ 'style': 'minimal',
\ 'border': 'rounded'
\ }

let content_opts = extend({
\ "row": border_opts.row + 1,
\ "height": border_opts.height - 2,
\ "col": border_opts.col + 2,
\ "width": border_opts.width - 4
\ }, border_opts, "keep")

let out_buffer = nvim_create_buf(v:false, v:true)
call nvim_buf_set_option(out_buffer, "filetype", a:filetype)
let user_window = nvim_get_current_win()
let output_window = nvim_open_win(out_buffer, v:true, content_opts)
if type(a:cmd) == v:t_list
call termopen(join(a:cmd, " "))
else
exec 'lua vim.api.nvim_chan_send(vim.api.nvim_open_term(0, {}),(io.open("'.a:cmd.'", "r"):read("*a"):gsub("\n", "\r\n")))'
endif
exec "setfiletype ".a:filetype
call nvim_set_current_win(user_window)
let output_win_id = nvim_win_get_number(output_window)
call setwinvar(output_win_id, "&winhl", "Normal:Normal")

let top = "" . repeat("", border_opts.width-2) . ""
let mid = "" . repeat(" ", border_opts.width-2) . ""
let bot = "" . repeat("", border_opts.width-2) . ""
let lines = [top] + repeat([mid], a:height-2) + [bot]
let s:buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(s:buf, 0, -1, v:true, lines)
let border_window = nvim_open_win(s:buf, v:false, border_opts)
let border_win_id = nvim_win_get_number(border_window)
call setwinvar(border_win_id, "&winhl", "Normal:Normal")
call matchadd("UltestBorder", ".*",100, -1, {"window": border_window})
call nvim_win_set_option(output_window, "winhl", "Normal:Normal,FloatBorder:UltestBorder")

let g:ultest#output_windows = [output_window, border_window]
let g:ultest#output_windows = [output_window]
endfunction
12 changes: 12 additions & 0 deletions doc/ultest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ Number of columns for terminal size where tests are run (default: 0) Set to
zero to not instruct runner on size of terminal. Note: It is up to the test
runner to respect these bounds

*g:ultest_output_max_width*
Max width of the output window (default: 0)

*g:ultest_output_max_height*
Max height of the output window (default: 0)

*g:ultest_output_min_width*
Min width of the output window (default: 0)

*g:ultest_output_min_height*
Min height of the output window (default: 0)

*g:ultest_show_in_file*
Enable sign/virtual text processor for tests. (default: 1)

Expand Down
21 changes: 21 additions & 0 deletions plugin/ultest.vim
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ let g:ultest_output_rows = get(g:, "ultest_output_rows", 0)
" Note: It is up to the test runner to respect these bounds
let g:ultest_output_cols = get(g:, "ultest_output_cols", 0)


""
" Max width of the output window
" (default: 0)
let g:ultest_output_max_width = get(g:, "ultest_output_max_width", 0)

""
" Max height of the output window
" (default: 0)
let g:ultest_output_max_height = get(g:, "ultest_output_max_height", 0)

""
" Min width of the output window
" (default: 0)
let g:ultest_output_min_width = get(g:, "ultest_output_min_width", 80)

""
" Min height of the output window
" (default: 0)
let g:ultest_output_min_height = get(g:, "ultest_output_min_height", 20)

"" Enable sign/virtual text processor for tests.
" (default: 1)
let g:ultest_show_in_file = get(g:, "ultest_show_in_file", 1)
Expand Down

0 comments on commit 971655d

Please sign in to comment.