mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-12 17:55:41 +08:00
feat(chat): improve vimchat ui
This commit is contained in:
parent
b3fa6a1356
commit
3fb1bba91f
@ -162,12 +162,53 @@ function! chat#windows#open() abort
|
||||
normal! :
|
||||
endfunction
|
||||
|
||||
function! s:get_str_with_width(str,width) abort
|
||||
let str = a:str
|
||||
let result = ''
|
||||
let tmp = ''
|
||||
for i in range(strchars(str))
|
||||
let tmp .= matchstr(str, '^.')
|
||||
if strwidth(tmp) > a:width
|
||||
return result
|
||||
else
|
||||
let result = tmp
|
||||
endif
|
||||
let str = substitute(str, '^.', '', 'g')
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! s:get_lines_with_width(str, width) abort
|
||||
let str = a:str
|
||||
let lines = []
|
||||
let line = ''
|
||||
let tmp = ''
|
||||
for i in range(strchars(str))
|
||||
let tmp .= matchstr(str, '^.')
|
||||
if strwidth(tmp) > a:width
|
||||
call add(lines, line)
|
||||
let tmp = matchstr(str, '^.')
|
||||
endif
|
||||
let line = tmp
|
||||
let str = substitute(str, '^.', '', 'g')
|
||||
endfor
|
||||
call add(lines, line)
|
||||
return lines
|
||||
endfunction
|
||||
|
||||
function! s:update_msg_screen() abort
|
||||
if s:msg_win_opened
|
||||
normal! gg"_dG
|
||||
for msg in s:messages
|
||||
if msg['room'] ==# s:current_channel
|
||||
call append(line('$'), '[' . msg['time'] . '] < ' . msg['user'] . ' > ' . msg['msg'])
|
||||
let msgs = filter(deepcopy(s:messages), 'v:val["room"] ==# s:current_channel')
|
||||
for msg in msgs
|
||||
let name = s:get_str_with_width(msg['user'], 13)
|
||||
let message = s:get_lines_with_width(msg['msg'], winwidth('$') - 36)
|
||||
let first_line = '[' . msg['time'] . '] ' . nr2char(9474) . repeat(' ', 13 - strwidth(name)) . name . ' ' . nr2char(9474) . ' ' . message[0]
|
||||
call append(line('$'), first_line)
|
||||
if len(message) > 1
|
||||
for l in message[1:]
|
||||
call append(line('$'), repeat(' ', 18) . ' ' . nr2char(9474) . ' ' .repeat(' ', 12) . ' ' . nr2char(9474) . ' ' . l)
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
normal! gg"_ddG
|
||||
|
@ -10,5 +10,5 @@
|
||||
syn match VimChatTime /\[\d\d\d\d-\d\d-\d\d\s\d\d\:\d\d]/
|
||||
syn match VimChatNick /\[\d\d\d\d-\d\d-\d\d\s\d\d\:\d\d]\s<[^>]*>/ contains=VimChatTime
|
||||
" hi def link vimChatMsg Comment
|
||||
hi def link VimChatTime String
|
||||
hi def link VimChatTime Comment
|
||||
hi def link VimChatNick Type
|
||||
|
Loading…
x
Reference in New Issue
Block a user