summaryrefslogtreecommitdiff
path: root/.vim/miniplugins/statusline.vim
blob: 980a65b143e50c639fb92a59f8064e5efd4f7498 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
" Needed settings
set laststatus=2
set timeoutlen=1000 ttimeoutlen=10
set noshowmode

" Logic

let leftcap = ''
let rightcap = ''
let leftmcap = ''
let rightmcap = ''

let g:activesl   = ''
let g:inactivesl = ''

" Mode {{{
	" Values are, in order, for: normal (default), insert, replace, visual modes
	"	[ctermfg, ctermbg]
	let s:modecolors = [
	\	['236', '117'],
	\	['236', '119'],
	\	['236', '203'],
	\	['236', '216'],
	\]

	let g:modestring = ''

	autocmd ColorScheme * hi SLMode  ctermfg=1 ctermbg=0
	autocmd ColorScheme * hi SLModeC ctermfg=1 ctermbg=0

	function! SLModeSetter()
		let cm = mode()
		let ind = 0
		 
		if cm == 'i'
			let ind = 1
		elseif cm == 'R'
			let ind = 2
			let cm = 'r'
		elseif cm == 'v'
			let ind = 3
		endif

		call hlset([#{name: 'SLMode',  ctermfg: s:modecolors[l:ind][0], ctermbg: s:modecolors[l:ind][1]}])
		call hlset([#{name: 'SLModeC', ctermfg: s:modecolors[l:ind][1], ctermbg: '239'}])
		let g:modestring = l:cm

		return ''
	endfunction

	let g:activesl   ..= '%{SLModeSetter()}%#SLModeC#%{leftcap}%#SLMode#%{modestring}%#SLModeC#%{rightcap}'
	                   "                   \______leftcap______/\________mode_______/\______rightcap_____/
	let g:inactivesl ..= '%#StatusLine#   '
" }}}

" Filename {{{
	let g:_filename = '%#StatusLine# %f %{rightmcap}'
	let g:activesl   ..= g:_filename
	let g:inactivesl ..= g:_filename
" }}}

" File stat {{{
	function! SLReadonly()
		return (&ft !~? 'vimfiler' && &readonly) ? ' ' : ''
	endfunction

	function! SLModified()
		return (&ft =~ 'vimfiler') ? '' : (&modified ? '' : (&modifiable ? '' : ''))
	endfunction

	let g:_filestat = ' %{SLReadonly()}%{SLModified()} '
	let g:activesl   ..= g:_filestat
	let g:inactivesl ..= g:_filestat
" }}}

" Middle separator {{{
	let g:activesl   ..= '%='
	let g:inactivesl ..= '%='
" }}}

" Filetype {{{
	let g:_filetype = '%{leftmcap} %{WebDevIconsGetFileTypeSymbol()} %{&ft} '
	let g:activesl   ..= g:_filetype
	let g:inactivesl ..= g:_filetype
" }}}

" Line and column count {{{
	autocmd ColorScheme * hi SLRowCol  ctermfg=238 ctermbg=244
	autocmd ColorScheme * hi SLRowColC ctermfg=244 ctermbg=239

	let g:_linecol = '%#SLRowColC#%{leftcap}%#SLRowCol#%l:%c%#SLRowColC#%{rightcap}'
	let g:activesl   ..= g:_linecol
	let g:inactivesl ..= g:_linecol
" }}}

" Statusline setting {{{
	set statusline=

	augroup SLModeAU
		au!
		au WinEnter,BufEnter * setlocal statusline=%!g:activesl
		au WinLeave,BufLeave * setlocal statusline=%!g:inactivesl
	augroup end
" }}}