Skip to content

Commit

Permalink
Changes made to reflec disabling progess bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jtw023 committed May 27, 2024
1 parent db47480 commit 27c49a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 79 deletions.
99 changes: 25 additions & 74 deletions autoload/db_ui/dbout.vim
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,8 @@ function! s:progress_tick(progress, timer) abort
if a:progress.icon_counter > 3
let a:progress.icon_counter = 0
endif
if !empty(g:db_ui_use_full_minutes_and_seconds)
let secs = a:progress.counter * 0.001
let minutes = string(floor(secs / 60))
let formattedminutes = substitute(minutes, '\.0$', '', '')
let seconds = string(((fmod(secs / 60, 1) * 60) / 100) * 100)
if formattedminutes > 0
if formattedminutes < 2
if seconds < 10
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query ---- '.formattedminutes.' minute '.seconds.' seconds '
else
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query --- '.formattedminutes.' minute '.seconds.' seconds '
endif
else
if seconds < 10
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query --- '.formattedminutes.' minutes '.seconds.' seconds '
else
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query -- '.formattedminutes.' minutes '.seconds.' seconds '
endif
endif
else
if seconds < 10
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query ------------- '.seconds.' seconds'
else
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query ------------ '.seconds.' seconds'
endif
endif
else
let secs = string(a:progress.counter * 0.001).'s'
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query - '.secs
endif
let secs = string(a:progress.counter * 0.001).'s'
let content = ' '.s:progress_icons[a:progress.icon_counter].' Execute query - '.secs
if has('nvim')
call nvim_buf_set_lines(a:progress.buf, 0, -1, v:false, [content])
else
Expand All @@ -269,17 +241,10 @@ endfunction

function! s:progress_winpos(win)
let pos = win_screenpos(a:win)
if !empty(g:db_ui_use_full_minutes_and_seconds)
return [
\ pos[0] + (winheight(a:win) / 2),
\ pos[1] + (winwidth(a:win) / 2) - (winwidth(a:win) / 5),
\ ]
else
return [
\ pos[0] + (winheight(a:win) / 2),
\ pos[1] + (winwidth(a:win) / 2) - 12,
\ ]
endif
return [
\ pos[0] + (winheight(a:win) / 2),
\ pos[1] + (winwidth(a:win) / 2) - 12,
\ ]
endfunction

function! s:progress_hide(...) abort
Expand Down Expand Up @@ -316,33 +281,17 @@ function! s:progress_show_neovim(path) abort
let progress = copy(s:progress)
let progress.outwin = outwin
let progress.buf = nvim_create_buf(v:false, v:true)
if !empty(g:db_ui_use_full_minutes_and_seconds)
call nvim_buf_set_lines(progress.buf, 0, -1, v:false, ['| Execute query --- 0 minutes 0 seconds'])
else
call nvim_buf_set_lines(progress.buf, 0, -1, v:false, ['| Execute query - 0.0s'])
endif
call nvim_buf_set_lines(progress.buf, 0, -1, v:false, ['| Execute query - 0.0s'])
let [row, col] = s:progress_winpos(outwin)
if !empty(g:db_ui_use_full_minutes_and_seconds)
let opts = {
\ 'relative': 'editor',
\ 'width': 43,
\ 'height': 1,
\ 'row': row - 2,
\ 'col': col,
\ 'focusable': v:false,
\ 'style': 'minimal'
\ }
else
let opts = {
\ 'relative': 'editor',
\ 'width': 24,
\ 'height': 1,
\ 'row': row - 2,
\ 'col': col,
\ 'focusable': v:false,
\ 'style': 'minimal'
\ }
endif
let opts = {
\ 'relative': 'editor',
\ 'width': 24,
\ 'height': 1,
\ 'row': row - 2,
\ 'col': col,
\ 'focusable': v:false,
\ 'style': 'minimal'
\ }
if has('nvim-0.5')
let opts.border = 'rounded'
endif
Expand Down Expand Up @@ -382,11 +331,13 @@ endfunction


if exists('*nvim_open_win') || exists('*popup_create')
augroup dbui_async_queries_dbout
autocmd!
autocmd User DBQueryPre call s:progress_show()
autocmd User DBQueryPost call s:progress_hide()
autocmd User *DBExecutePre call s:progress_show(expand('<amatch>:h'))
autocmd User *DBExecutePost call s:progress_hide(expand('<amatch>:h'))
augroup END
if empty(g:db_ui_disable_progress_bar)
augroup dbui_async_queries_dbout
autocmd!
autocmd User DBQueryPre call s:progress_show()
autocmd User DBQueryPost call s:progress_hide()
autocmd User *DBExecutePre call s:progress_show(expand('<amatch>:h'))
autocmd User *DBExecutePost call s:progress_hide(expand('<amatch>:h'))
augroup END
endif
endif
9 changes: 5 additions & 4 deletions doc/dadbod-ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,11 @@ g:db_ui_use_postgres_views

Default value: 1

*g:db_ui_query_execute_full_minutes_and_seconds*
g:db_ui_query_execute_full_minutes_and_seconds
By default query run time is shown in seconds only.
To show full minutes and seconds on query execute set this value to 1.
*g:db_ui_disable_progress_bar*
g:db_ui_disable_progress_bar
Toggle query execution progress bar.
This option is available to prevent conflict with a custom progress bar
or if you want to disable the progress entirely set to 1.

Default value: 0

Expand Down
2 changes: 1 addition & 1 deletion plugin/db_ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if exists('g:loaded_dbui')
endif
let g:loaded_dbui = 1

let g:db_ui_query_execute_full_minutes_and_seconds = get(g:, 'db_ui_query_execute_full_minutes_and_seconds', 0)
let g:db_ui_disable_progress_bar = get(g:, 'db_ui_disable_progress_bar', 0)
let g:db_ui_use_postgres_views = get(g:, 'db_ui_use_postgres_views', 1)
let g:db_ui_notification_width = get(g:, 'db_ui_notification_width', 40)
let g:db_ui_winwidth = get(g:, 'db_ui_winwidth', 40)
Expand Down

0 comments on commit 27c49a6

Please sign in to comment.