-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_color_switcher.vim
60 lines (51 loc) · 1.32 KB
/
auto_color_switcher.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let s:save_cpo = &cpo
set cpo&vim
if exists('g:loaded_auto_color_switcher')
finish
endif
if exists('g:auto_color_switcher#disable')
if g:auto_color_switcher#disable == v:true
finish
endif
else
let g:auto_color_switcher#disable = v:false
endif
if exists('g:auto_color_switcher#binary_path')
let s:exe = g:auto_color_switcher#binary_path
else
let s:exe = expand('<sfile>:p:h:h')..'/bin/auto_color_switcher'
if s:exe == expand('<sfile>:p:h:h')
echo "auto_color_switcher : couldn't find binary"
finish
endif
endif
if exists('g:auto_color_switcher#command')
else
let g:auto_color_switcher#command = {
\ 'light': 'set background=light',
\ 'dark' : 'set background=dark'
\}
endif
function! s:CallBack(ch, msg)
if g:auto_color_switcher#disable == v:true
return
endif
if a:msg == "light"
call execute(g:auto_color_switcher#command['light'])
else
call execute(g:auto_color_switcher#command['dark'])
endif
redraw
endfunction
function! s:CallBackNeoVim(j, d, e)
call s:CallBack(a:j, a:d[0])
endfunction
" s:jobはデバグ用です
if has('nvim')
let s:job = jobstart(s:exe, {"on_stdout": function('s:CallBackNeoVim')})
else
let s:job = job_start(s:exe, {"out_cb": function('s:CallBack')})
endif
let g:loaded_auto_color_switcher = 1
let &cpo = s:save_cpo
unlet s:save_cpo