mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:50:04 +08:00
docs(notify): support multiple line msg and msg list
This commit is contained in:
parent
ee82313ec0
commit
ffdc24702d
@ -14,9 +14,9 @@ scriptencoding utf-8
|
|||||||
"
|
"
|
||||||
" notify({msg} [, {Color}[, {option}]])
|
" notify({msg} [, {Color}[, {option}]])
|
||||||
"
|
"
|
||||||
" Use floating windows to display notification {msg}. The {msg} should a no
|
" Use floating windows to display notification {msg}. The {msg} can be a
|
||||||
" empty string. {Color} is the name of highlight ground defined in Vim. The
|
" string or a list of string. {Color} is the name of highlight ground defined
|
||||||
" {option} is a dictionary which support following key:
|
" in Vim. The {option} is a dictionary which support following key:
|
||||||
"
|
"
|
||||||
" - `winblend`: enable transparency for the notify windows. Valid values
|
" - `winblend`: enable transparency for the notify windows. Valid values
|
||||||
" are in the range of 0 to 100. Default is 0.
|
" are in the range of 0 to 100. Default is 0.
|
||||||
@ -102,7 +102,7 @@ function! s:self.increase_window(...) abort
|
|||||||
if self.notification_width <= self.notify_max_width && self.win_is_open()
|
if self.notification_width <= self.notify_max_width && self.win_is_open()
|
||||||
let self.notification_width += min([float2nr((self.notify_max_width - self.notification_width) * 1 / 20), float2nr(self.notify_max_width)])
|
let self.notification_width += min([float2nr((self.notify_max_width - self.notification_width) * 1 / 20), float2nr(self.notify_max_width)])
|
||||||
call self.__buffer.buf_set_lines(self.border.bufnr, 0 , -1, 0,
|
call self.__buffer.buf_set_lines(self.border.bufnr, 0 , -1, 0,
|
||||||
\ self.draw_border(self.title, self.notification_width, len(self.message)))
|
\ self.draw_border(self.title, self.notification_width, s:msg_real_len(self.message)))
|
||||||
call self.redraw_windows()
|
call self.redraw_windows()
|
||||||
call timer_start(10, self.increase_window, {'repeat' : 1})
|
call timer_start(10, self.increase_window, {'repeat' : 1})
|
||||||
endif
|
endif
|
||||||
@ -162,16 +162,33 @@ function! s:self.close_all() abort
|
|||||||
let self.notification_width = 1
|
let self.notification_width = 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:is_list_of_string(t) abort
|
||||||
|
if type(a:t) == type([])
|
||||||
|
for t in a:t
|
||||||
|
if type(t) !=# type('')
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:self.notify(msg, ...) abort
|
function! s:self.notify(msg, ...) abort
|
||||||
" check if neovim/vim support following windows
|
" check if neovim/vim support following windows
|
||||||
if !self.__floating.exists()
|
if !self.__floating.exists()
|
||||||
echo a:msg
|
echo a:msg
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
" multiple line message should be signal msg
|
||||||
|
" if the a:msg is a list, it will be append to self.message
|
||||||
|
if s:is_list_of_string(a:msg)
|
||||||
|
call extend(self.message, a:msg)
|
||||||
|
elseif type(a:msg) == type('')
|
||||||
|
call add(self.message, a:msg)
|
||||||
|
endif
|
||||||
if self.notify_max_width ==# 0
|
if self.notify_max_width ==# 0
|
||||||
let self.notify_max_width = &columns * 0.35
|
let self.notify_max_width = &columns * 0.35
|
||||||
endif
|
endif
|
||||||
call extend(self.message, split(a:msg, "\n"))
|
|
||||||
let self.notification_color = get(a:000, 0, 'Normal')
|
let self.notification_color = get(a:000, 0, 'Normal')
|
||||||
let options = get(a:000, 1, {})
|
let options = get(a:000, 1, {})
|
||||||
let self.winblend = get(options, 'winblend', self.winblend)
|
let self.winblend = get(options, 'winblend', self.winblend)
|
||||||
@ -189,7 +206,23 @@ function! s:self.notify(msg, ...) abort
|
|||||||
call setbufvar(self.border.bufnr, '&bufhidden', 'wipe')
|
call setbufvar(self.border.bufnr, '&bufhidden', 'wipe')
|
||||||
call extend(s:notifications, {self.hashkey : self})
|
call extend(s:notifications, {self.hashkey : self})
|
||||||
call self.increase_window()
|
call self.increase_window()
|
||||||
call timer_start(self.timeout, self.close, {'repeat' : len(split(a:msg, "\n"))})
|
call timer_start(self.timeout, self.close, {'repeat' : type(a:msg) == type([]) ? len(a:msg) : 1})
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:msg_real_len(msg) abort
|
||||||
|
let l = 0
|
||||||
|
for m in a:msg
|
||||||
|
let l += len(split(m, "\n"))
|
||||||
|
endfor
|
||||||
|
return l
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:message_body(msg) abort
|
||||||
|
let b = []
|
||||||
|
for m in a:msg
|
||||||
|
call extend(b, split(m, "\n"))
|
||||||
|
endfor
|
||||||
|
return b
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:self.redraw_windows() abort
|
function! s:self.redraw_windows() abort
|
||||||
@ -199,7 +232,7 @@ function! s:self.redraw_windows() abort
|
|||||||
let self.begin_row = 2
|
let self.begin_row = 2
|
||||||
for hashkey in keys(s:notifications)
|
for hashkey in keys(s:notifications)
|
||||||
if hashkey !=# self.hashkey
|
if hashkey !=# self.hashkey
|
||||||
let self.begin_row += len(s:notifications[hashkey].message) + 2
|
let self.begin_row += s:msg_real_len(s:notifications[hashkey].message) + 2
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
@ -209,7 +242,7 @@ function! s:self.redraw_windows() abort
|
|||||||
\ {
|
\ {
|
||||||
\ 'relative': 'editor',
|
\ 'relative': 'editor',
|
||||||
\ 'width' : self.notification_width,
|
\ 'width' : self.notification_width,
|
||||||
\ 'height' : len(self.message),
|
\ 'height' : s:msg_real_len(self.message),
|
||||||
\ 'row': self.begin_row + 1,
|
\ 'row': self.begin_row + 1,
|
||||||
\ 'highlight' : self.notification_color,
|
\ 'highlight' : self.notification_color,
|
||||||
\ 'focusable' : v:false,
|
\ 'focusable' : v:false,
|
||||||
@ -219,7 +252,7 @@ function! s:self.redraw_windows() abort
|
|||||||
\ {
|
\ {
|
||||||
\ 'relative': 'editor',
|
\ 'relative': 'editor',
|
||||||
\ 'width' : self.notification_width + 2,
|
\ 'width' : self.notification_width + 2,
|
||||||
\ 'height' : len(self.message) + 2,
|
\ 'height' : s:msg_real_len(self.message) + 2,
|
||||||
\ 'row': self.begin_row,
|
\ 'row': self.begin_row,
|
||||||
\ 'col': &columns - self.notification_width - 2,
|
\ 'col': &columns - self.notification_width - 2,
|
||||||
\ 'highlight' : 'VertSplit',
|
\ 'highlight' : 'VertSplit',
|
||||||
@ -236,7 +269,7 @@ function! s:self.redraw_windows() abort
|
|||||||
\ {
|
\ {
|
||||||
\ 'relative': 'editor',
|
\ 'relative': 'editor',
|
||||||
\ 'width' : self.notification_width,
|
\ 'width' : self.notification_width,
|
||||||
\ 'height' : len(self.message),
|
\ 'height' : s:msg_real_len(self.message),
|
||||||
\ 'row': self.begin_row + 1,
|
\ 'row': self.begin_row + 1,
|
||||||
\ 'highlight' : self.notification_color,
|
\ 'highlight' : self.notification_color,
|
||||||
\ 'col': &columns - self.notification_width - 1,
|
\ 'col': &columns - self.notification_width - 1,
|
||||||
@ -246,7 +279,7 @@ function! s:self.redraw_windows() abort
|
|||||||
\ {
|
\ {
|
||||||
\ 'relative': 'editor',
|
\ 'relative': 'editor',
|
||||||
\ 'width' : self.notification_width + 2,
|
\ 'width' : self.notification_width + 2,
|
||||||
\ 'height' : len(self.message) + 2,
|
\ 'height' : s:msg_real_len(self.message) + 2,
|
||||||
\ 'row': self.begin_row,
|
\ 'row': self.begin_row,
|
||||||
\ 'col': &columns - self.notification_width - 2,
|
\ 'col': &columns - self.notification_width - 2,
|
||||||
\ 'highlight' : 'VertSplit',
|
\ 'highlight' : 'VertSplit',
|
||||||
@ -259,8 +292,8 @@ function! s:self.redraw_windows() abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
call self.__buffer.buf_set_lines(self.border.bufnr, 0 , -1, 0,
|
call self.__buffer.buf_set_lines(self.border.bufnr, 0 , -1, 0,
|
||||||
\ self.draw_border(self.title, self.notification_width, len(self.message)))
|
\ self.draw_border(self.title, self.notification_width, s:msg_real_len(self.message)))
|
||||||
call self.__buffer.buf_set_lines(self.bufnr, 0 , -1, 0, self.message)
|
call self.__buffer.buf_set_lines(self.bufnr, 0 , -1, 0, s:message_body(self.message))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
@ -6570,9 +6570,9 @@ The notification api for SpaceVim
|
|||||||
|
|
||||||
notify({msg} [, {Color}[, {option}]])
|
notify({msg} [, {Color}[, {option}]])
|
||||||
|
|
||||||
Use floating windows to display notification {msg}. The {msg} should a no
|
Use floating windows to display notification {msg}. The {msg} can be a string
|
||||||
empty string. {Color} is the name of highlight ground defined in Vim. The
|
or a list of string. {Color} is the name of highlight ground defined in Vim.
|
||||||
{option} is a dictionary which support following key:
|
The {option} is a dictionary which support following key:
|
||||||
|
|
||||||
`winblend`: enable transparency for the notify windows. Valid values are in
|
`winblend`: enable transparency for the notify windows. Valid values are in
|
||||||
the range of 0 to 100. Default is 0.
|
the range of 0 to 100. Default is 0.
|
||||||
|
Loading…
Reference in New Issue
Block a user