diff --git a/bundle/vim-chat/autoload/chat/windows.vim b/bundle/vim-chat/autoload/chat/windows.vim index 9cacf52a3..28bf201cb 100644 --- a/bundle/vim-chat/autoload/chat/windows.vim +++ b/bundle/vim-chat/autoload/chat/windows.vim @@ -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 diff --git a/bundle/vim-chat/syntax/vimchat.vim b/bundle/vim-chat/syntax/vimchat.vim index 7e9a980c2..59ba1405f 100644 --- a/bundle/vim-chat/syntax/vimchat.vim +++ b/bundle/vim-chat/syntax/vimchat.vim @@ -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