Closed jtw023 closed 6 months ago
Instead of adding this as an option, I'd rather leave it to the user to code their own progress bar in case they need it.
For example, you can hook into *DBExecutePre
and *DBExecutePost
in your vimrc and write a logic for the progress bar however you want.
This just doesn't seem like an option that a lot of people would use.
We can add an option to disable the built in progress bar to not interfere with a custom one, something like g:db_ui_disable_progress_bar = 0
.
Set default of g:db_ui_disable_progress_bar
to 0 and made code plus documentation changes to disable progress bar. However, I tried to source the following file in my vimrc which did not work. Do you know how I can overwrite the current autocommands without touching autoload/db_ui/dbout.vim
?
Once I get this working I would like to update the documentation to show this process and how exactly a user can do this.
let g:db_ui_disable_progress_bar = 1
let g:db_ui_use_postgres_views = 0
let g:db_ui_force_echo_notifications = 1
let g:db_ui_use_nerd_fonts = 1
let g:db_ui_execute_on_save = 0
let g:db_ui_save_location = '/home/jordan/bitbucket_repos/jordanw/'
" let g:completion_matching_strategy_list = {'exact', 'substring'}
let g:completion_matching_ignore_case = 1
" NOTE: Progress timer
function! s:progress_tick(progress, timer) abort
let a:progress.counter += 100
if a:progress.icon_counter > 3
let a:progress.icon_counter = 0
endif
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
if has('nvim')
call nvim_buf_set_lines(a:progress.buf, 0, -1, v:false, [content])
else
call popup_settext(a:progress.win, content)
endif
let a:progress.icon_counter += 1
endfunction
function! s:progress_winpos(win)
let pos = win_screenpos(a:win)
return [
\ pos[0] + (winheight(a:win) / 2),
\ pos[1] + (winwidth(a:win) / 2) - (winwidth(a:win) / 5),
\ ]
endfunction
function! s:progress_hide(...) abort
let bufname = a:0 > 0 ? a:1 : bufname()
let progress = get(s:progress_buffers, bufname, {})
if empty(progress)
return
endif
if has('nvim')
silent! call nvim_win_close(progress.win, v:true)
else
silent! call popup_close(progress.win)
endif
silent! call timer_stop(progress.timer)
unlet! s:progress_buffers[bufname]
call s:progress_reset_positions()
endfunction
function! s:progress_show_neovim(path) abort
let bufname = !empty(a:path) ? a:path : bufname()
let outwin = win_getid(bufwinnr(bufname))
let progress = copy(s:progress)
let progress.outwin = outwin
let progress.buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(progress.buf, 0, -1, v:false, ['| Execute query --- 0 minutes 0 seconds'])
let [row, col] = s:progress_winpos(outwin)
let opts = {
\ 'relative': 'editor',
\ 'width': 43,
\ 'height': 1,
\ 'row': row - 2,
\ 'col': col,
\ 'focusable': v:false,
\ 'style': 'minimal'
\ }
if has('nvim-0.5')
let opts.border = 'rounded'
endif
let progress.win = nvim_open_win(progress.buf, v:false, opts)
let progress.timer = timer_start(100, function('s:progress_tick', [progress]), { 'repeat': -1 })
let s:progress_buffers[bufname] = progress
endfunction
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
Changes look good, thanks!
Regarding the example, feel free to create a wiki page, I opened it up so you should have permission to do it.
What does this expand('<amatch>:h')
do in:
autocmd User *DBExecutePre call s:progress_show(expand('<amatch>:h'))
autocmd User *DBExecutePost call s:progress_hide(expand('<amatch>:h'))
I think I'm running into a problem there. When I try to run a query the progress bar pops up as expected but my queries don't actually run against Redshift.
Every time the query is ran, it triggers an autocmd with name similar to this:
/tmp/nvim/CmkUz1/11.dbout/DBExecutePre
<amatch>
returns the autocmd name, and with :h
we parse the file name only:
/tmp/nvim/CmkUz1/11.dbout/DBExecutePre
-> /tmp/nvim/CmkUz1/11.dbout
I'm not sure what you mean by queries not running against Redshift. Do they run if you do not use custom progress bar?
If I do not source the file where I define my custom progress bar the queries run against Redshift exactly as expected. This happens with the new db_ui_disable_progress_bar
variable set to 1 or to 0. The issue is nothing that we just committed.
The only time I run into the issue is when I source the custom progress bar. See the video for an example. The timer runs but nothing is actually running. I checked Redshift as well and nothing from my user is running on that cluster. I also cannot cancel like I normally can.
https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/271d0cf3-42d5-4935-87da-5d1ac3be8336
If everything works normally when you do not add your progress bar, then it's probably some issue in there. Does cancelling work when you just disable the built in progress bar but not add your own?
Does cancelling work when you just disable the built in progress bar but not add your own?
Yep! There is no issue at all unless I source my own progress bar.
I think the issue is related to me not calling db_ui#dbout#jump_to_foreign_table()
in my init.vim. However, when I do that it tells me that b:db is an undefined variable.
You don't need to call that function for the progress bar. Copy this chunk of built in code and adapt it to your needs https://github.com/kristijanhusak/vim-dadbod-ui/blob/0dc68d9225a70d42f8645049482e090c1a8dce25/autoload/db_ui/dbout.vim?plain=1#L216-L344
Solved it. Will look into creating a wiki page this week.
Another customization I've made is to show full minutes and seconds on query execute. This would be a completely new feature but it's something I use so I thought I'd put it into a pull request in case you'd like to merge it.
All it does is adjust the screen to show the full time of your query rather than only the seconds.
Examples:
Less than 10 seconds into the query: ![LessThan10S](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/d336624c-1b6b-46fb-afdf-b56643836e9e) Less than 1 minute into the query: ![LessThan1M](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/a17c1cce-4eb1-4315-852e-c677041ce957) Less than 1 minute and 10 seconds into the query: ![LessThan1M10S](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/706ae9bf-4b77-4765-84d4-9a29db8a5506) Less than 2 minutes into the query: ![LessThan2M](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/7996902b-0b89-4679-bb60-330e1e2ba1e0) Less than 2 minutes and 10 seconds into the query: ![LessThan2M10S](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/ee61da81-2453-4248-bd33-f5efc17e5777) More than 2 minutes and 10 seconds into the query: ![MoreThan2M10S](https://github.com/kristijanhusak/vim-dadbod-ui/assets/59935328/ca303b02-0547-497f-95fe-d01b4185ef11)