summaryrefslogtreecommitdiff
path: root/plugin/statusline.vim
blob: a5264a4392ff77f28a36e07a53bcd5dd917f2873 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
scriptencoding utf-8

" statusline

let g:currentmode={
            \ 'n'  : 'NORMAL ',
            \ 'no' : 'N·OPERATOR PENDING ',
            \ 'v'  : 'VISUAL ',
            \ 'V'  : 'V·LINE ',
            \ '' : 'V·BLOCK ',
            \ 's'  : 'SELECT ',
            \ 'S'  : 'S·LINE ',
            \ '' : 'S·BLOCK ',
            \ 'i'  : 'INSERT ',
            \ 'R'  : 'REPLACE ',
            \ 'Rv' : 'V·REPLACE ',
            \ 'c'  : 'COMMAND ',
            \ 'cv' : 'VIM EX ',
            \ 'ce' : 'EX ',
            \ 'r'  : 'PROMPT ',
            \ 'rm' : 'MORE ',
            \ 'r?' : 'CONFIRM ',
            \ '!'  : 'SHELL ',
            \ 't'  : 'TERMINAL '}

hi PrimaryBlock       ctermfg=00    ctermbg=6
hi SecondaryBlock     ctermfg=07    ctermbg=10
hi Blanks             ctermfg=08    ctermbg=0

hi User1             ctermfg=01    ctermbg=0
hi User2             ctermfg=02    ctermbg=0
hi User3             ctermfg=03    ctermbg=0
hi User4             ctermfg=12    ctermbg=0
hi User5             ctermfg=05    ctermbg=0
hi User6             ctermfg=06    ctermbg=0
hi User7             ctermfg=07    ctermbg=0
hi User8             ctermfg=08    ctermbg=0
hi User9             ctermfg=00    ctermbg=0

highlight EndOfBuffer ctermfg=black ctermbg=black

function! ReadOnly() abort
    if !&modifiable && &readonly
        return ' RO'
    elseif &modifiable && &readonly
        return 'RO'
    elseif !&modifiable && !&readonly
        return ''
    else
        return ''
    endif
endfunction

function! Filepath() abort
    let l:basename = expand('%:h')
    let l:filename = expand('%:t')
    let l:extension = expand('%:e')
    let l:prefix = (l:basename ==# '' || l:basename ==# '.') ?
                \ '' : substitute(l:basename . '/', '\C^' . $HOME, '~', '')

    if empty(l:prefix) && empty(l:filename)
        return printf('%%4*%%f%%*%s %%m%%*', '%4*')
    elseif empty(l:prefix)
        return printf('%%4*%%f%%*%s %%m%%*', '%6*')
    else
        return printf('%%4*%s%%*%s%s%%*', l:prefix, &modified ? '%6*' : '%4*', l:filename)
    endif
endfunction

function! QuickFixStatus() abort
    let l:qfl=getqflist()
    let l:qftitle = getqflist({'title' : 0}).title
    if len(qfl) != 0
        return l:qftitle
    else 
        return ''
endfunction

function! LinterStatus() abort
    let sl = ''
    let msgs = []
    if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
        let errs = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })")
        let warns = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })")
        if errs != 0
            call add(msgs, printf('%%5*%s×%%* ', errs))
        endif
        if warns != 0
            call add(msgs, printf('%%3*%s!%%* ', warns))
        endif
        return join(msgs, '')
    else
        return ''
    endif
endfunction

function! StatusLine(mode) abort
  let l:line=''

  " help or man pages
  if &filetype ==# 'help' || &filetype ==# 'man'
    let l:line.=' %#StatusLineNC# ['. &filetype .'] %f '
    return l:line
  endif

  " active
  if a:mode ==# 'active'
    let l:line.=Filepath()
    let l:line.='%5*'
    let l:line.=QuickFixStatus()

    let l:line.='%5*'
    let l:line.=' %{ReadOnly()} %w%*'
    let l:line.='%9* %=%*'

    let l:line.=' ' . '%7*%l,%c%*' . ' '
    let l:line.=LinterStatus()
    let l:line.='%4*'. &filetype

  else
    " inactive
    let l:line.='%#Blanks#'
    let l:line.='%f %5*%m%*'
    let l:line.='%#Blanks# %=%*'
  endif

  let l:line.='%*'

  return l:line
endfunction

set statusline=%!StatusLine('active')
augroup MyStatusLine
  autocmd!
  autocmd WinEnter * setl statusline=%!StatusLine('active')
  autocmd WinLeave * setl statusline=%!StatusLine('inactive')
augroup END