├── corona-stats.png ├── README.md └── plugin └── corona-stats.vim /corona-stats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattn/vim-corona-stats/HEAD/corona-stats.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-corona-stats 2 | 3 | 新型コロナ感染者状況を表示します。 4 | 5 | ## Usage 6 | 7 | ``` 8 | :CoronaStats 9 | ``` 10 | 11 | ![](https://raw.githubusercontent.com/mattn/vim-corona-stats/master/corona-stats.png) 12 | 13 | ## Requirements 14 | 15 | * curl 16 | 17 | ## License 18 | 19 | MIT 20 | 21 | ## Author 22 | 23 | Yasuhiro Matsumoto (a.k.a. mattn) 24 | -------------------------------------------------------------------------------- /plugin/corona-stats.vim: -------------------------------------------------------------------------------- 1 | function! s:corona_stats() abort 2 | let l:lines = [] 3 | let l:keys = [ 4 | \ ['country', '国', 0], 5 | \ ['cases', '感染者数(累計)', 0], 6 | \ ['todayCases', '感染者数(本日)', 1], 7 | \ ['deaths', '死亡者数(累計)', 0], 8 | \ ['todayDeaths', '死亡者数(本日)', 1], 9 | \ ['recovered', '退院者数', 0], 10 | \] 11 | call add(l:lines, map(deepcopy(l:keys), 'v:val[1]')) 12 | 13 | let l:contents = system('curl -s "https://corona-stats.online?format=json"') 14 | let l:resp = json_decode(l:contents) 15 | for l:row in l:resp.data + [l:resp.worldStats] 16 | call add(l:lines, map(deepcopy(l:keys), 'l:row[v:val[0]]')) 17 | endfor 18 | let l:h = range(len(l:lines[0])) 19 | for l:c in range(len(l:lines[0])) 20 | let l:m = 0 21 | let l:w = range(len(l:lines)) 22 | for l:r in range(len(l:w)) 23 | let l:w[l:r] = strdisplaywidth(l:lines[l:r][l:c] . ' ') 24 | let l:m = max([l:m, l:w[l:r]]) 25 | endfor 26 | for l:r in range(len(l:w)) 27 | let l:mark = ' ' 28 | if l:keys[l:c][2] ==# 1 29 | if l:lines[l:r][l:c] > 0 30 | let l:mark = ' ^' 31 | elseif l:lines[l:r][l:c] < -0 32 | let l:mark = ' v' 33 | endif 34 | endif 35 | if l:c > 0 36 | let l:lines[l:r][l:c] = repeat(' ', l:m - l:w[l:r]) . l:lines[l:r][l:c] . l:mark 37 | else 38 | let l:lines[l:r][l:c] = l:lines[l:r][l:c] . repeat(' ', l:m - l:w[l:r]) . l:mark 39 | endif 40 | endfor 41 | let l:h[l:c] = repeat('-', strdisplaywidth(l:lines[0][l:c])) 42 | endfor 43 | for l:n in range(len(l:lines)) 44 | let l:lines[l:n] = '|' . join(l:lines[l:n], '|') . '|' 45 | endfor 46 | call insert(l:lines, '|' . join(l:h, '|') . '|', 1) 47 | call insert(l:lines, '|' . join(l:h, '|') . '|', len(l:lines)-1) 48 | silent new 49 | file __CORONA_STATS__ 50 | setlocal buftype=nofile nolist nonumber bufhidden=wipe noswapfile buflisted filetype= 51 | silent call append(0, l:lines) 52 | normal! gg 53 | endfunction 54 | command! CoronaStats call s:corona_stats() 55 | --------------------------------------------------------------------------------