diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim index 221a323..2db7cfe 100644 --- a/autoload/db_ui.vim +++ b/autoload/db_ui.vim @@ -384,7 +384,7 @@ function! s:dbui.connect(db) abort try let query_time = reltime() - call db_ui#notifications#info('Connecting to db '.a:db.name.'...', { 'echo': 1 }) + call db_ui#notifications#info('Connecting to db '.a:db.name.'...') let a:db.conn = db#connect(a:db.url) let a:db.conn_error = '' call db_ui#notifications#info('Connected to db '.a:db.name.' after '.split(reltimestr(reltime(query_time)))[0].' sec.') diff --git a/autoload/db_ui/drawer.vim b/autoload/db_ui/drawer.vim index 4b30d2b..7eadf1c 100644 --- a/autoload/db_ui/drawer.vim +++ b/autoload/db_ui/drawer.vim @@ -311,15 +311,15 @@ function! s:drawer.render(...) abort if get(opts, 'dbs', 0) let query_time = reltime() - call db_ui#notifications#info('Refreshing all databases...', { 'echo': 1 }) + call db_ui#notifications#info('Refreshing all databases...') call self.dbui.populate_dbs() call db_ui#notifications#info('Refreshed all databases after '.split(reltimestr(reltime(query_time)))[0].' sec.') endif if !empty(get(opts, 'db_key_name', '')) - let query_time = reltime() let db = self.dbui.dbs[opts.db_key_name] - call db_ui#notifications#info('Refreshing database '.db.name.'...', {'echo': 1 }) + call db_ui#notifications#info('Refreshing database '.db.name.'...') + let query_time = reltime() let self.dbui.dbs[opts.db_key_name] = self.populate(db) call db_ui#notifications#info('Refreshed database '.db.name.' after '.split(reltimestr(reltime(query_time)))[0].' sec.') endif diff --git a/autoload/db_ui/notifications.vim b/autoload/db_ui/notifications.vim index bc21eee..2b0109a 100644 --- a/autoload/db_ui/notifications.vim +++ b/autoload/db_ui/notifications.vim @@ -9,9 +9,14 @@ let s:width = g:db_ui_notification_width "Default notification width let s:pos = 'bot'.g:db_ui_win_position "Default position for notification let s:title = '[DBUI]' "Title of notification let s:last_msg = '' +let s:use_nvim_notify = g:db_ui_use_nvim_notify let s:colors_set = 0 +if s:use_nvim_notify && !has('nvim') + echoerr "Option db_ui_use_nvim_notify is supported only in neovim" +endif + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Public API, adapt names to your needs " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -47,16 +52,20 @@ function! s:notification(msg, opts) abort return endif - if !s:colors_set - call s:setup_colors() - let s:colors_set = 1 - endif - let use_echo = get(a:opts, 'echo', 0) if !use_echo let use_echo = g:db_ui_force_echo_notifications endif + if s:use_nvim_notify && !use_echo + return s:notification_nvim_notify(a:msg, a:opts) + endif + + if !s:colors_set + call s:setup_colors() + let s:colors_set = 1 + endif + if s:neovim_float && !use_echo return s:notification_nvim(a:msg, a:opts) endif @@ -79,6 +88,16 @@ function! s:nvim_close() abort silent! call timer_stop(s:timer) endfunction +function! s:notification_nvim_notify(msg, opts) abort + let type = get(a:opts, 'type', 'info') + let title = get(a:opts, 'title', s:title) + let opts = { 'title': title } + if get(a:opts, 'delay') + let opts.timeout = { 'timeout': a:opts.delay } + endif + return luaeval('vim.notify(_A[1], _A[2], _A[3])', [a:msg, type, opts]) +endfunction + function! s:notification_nvim(msg, opts) abort let width = get(a:opts, 'width', s:width) let title = get(a:opts, 'title', s:title) diff --git a/autoload/db_ui/query.vim b/autoload/db_ui/query.vim index 1f53bbb..5a73391 100644 --- a/autoload/db_ui/query.vim +++ b/autoload/db_ui/query.vim @@ -237,7 +237,7 @@ function! s:query.print_query_time() abort return endif let self.last_query_time = split(reltimestr(reltime(self.last_query_start_time)))[0] - call db_ui#notifications#info('Executing query...Done after '.self.last_query_time.' sec.') + call db_ui#notifications#info('Done after '.self.last_query_time.' sec.') endfunction function! s:query.execute_lines(db, lines, is_visual_mode) abort diff --git a/doc/dadbod-ui.txt b/doc/dadbod-ui.txt index f1d3129..09cfe94 100644 --- a/doc/dadbod-ui.txt +++ b/doc/dadbod-ui.txt @@ -109,6 +109,7 @@ DBUILastQueryInfo *DBUIHideNotifications* DBUIHideNotifications Hide all floating notifications that are currently shown. + Does not work with `vim.notify` and `echo` mode `:DBUIHideNotifications` @@ -703,6 +704,12 @@ g:db_ui_force_echo_notifications Notifications are shown via popups when supported. To force echoing messages to command line set this value to 1. + Default value: `0` + + *g:db_ui_use_nvim_notify* +g:db_ui_use_nvim_notify + Use Neovim's `vim.notify` API for notifications. + Default value: `0` *g:db_ui_hide_schemas* diff --git a/plugin/db_ui.vim b/plugin/db_ui.vim index 710476f..fabe6a6 100644 --- a/plugin/db_ui.vim +++ b/plugin/db_ui.vim @@ -19,6 +19,7 @@ let g:db_ui_show_help = get(g:, 'db_ui_show_help', 1) let g:db_ui_use_nerd_fonts = get(g:, 'db_ui_use_nerd_fonts', 0) let g:db_ui_execute_on_save = get(g:, 'db_ui_execute_on_save', 1) let g:db_ui_force_echo_notifications = get(g:, 'db_ui_force_echo_notifications', 0) +let g:db_ui_use_nvim_notify = get(g:, 'db_ui_use_nvim_notify', 0) let g:Db_ui_buffer_name_generator = get(g:, 'Db_ui_buffer_name_generator', 0) let g:db_ui_debug = get(g:, 'db_ui_debug', 0) let g:db_ui_hide_schemas = get(g:, 'db_ui_hide_schemas', [])