mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 08:50:04 +08:00
Update statusline layer
This commit is contained in:
parent
852d9559ab
commit
9d908e74b2
@ -125,11 +125,8 @@ function! SpaceVim#autocmds#VimEnter() abort
|
|||||||
endfor
|
endfor
|
||||||
if get(g:, '_spacevim_statusline_loaded', 0) == 1
|
if get(g:, '_spacevim_statusline_loaded', 0) == 1
|
||||||
set laststatus=2
|
set laststatus=2
|
||||||
set statusline=%!ActiveStatus()
|
call SpaceVim#layers#core#statusline#def_colors()
|
||||||
hi User1 guibg=#afd700 guifg=#005f00
|
set statusline=%!SpaceVim#layers#core#statusline#get(1)
|
||||||
hi User2 guibg=#005f00 guifg=#afd700
|
|
||||||
hi User3 guibg=#222222 guifg=#005f00
|
|
||||||
hi User4 guibg=#222222 guifg=#d0d0d0
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -1,65 +1,109 @@
|
|||||||
" statusline
|
" statusline
|
||||||
|
scriptencoding utf-8
|
||||||
let g:_spacevim_statusline_loaded = 1
|
let g:_spacevim_statusline_loaded = 1
|
||||||
|
" APIs
|
||||||
|
let s:MESSLETTERS = SpaceVim#api#import('messletters')
|
||||||
|
|
||||||
function! ActiveStatus()
|
" init
|
||||||
let statusline=""
|
let s:loaded_modes = ['⊝']
|
||||||
let statusline.="%1*"
|
let s:modes = [
|
||||||
let statusline.="%(%{'help'!=&filetype?'\ \ '.bufnr('%'):''}\ %)"
|
\ {
|
||||||
let statusline.="%2*"
|
\ 'name' : '⊝',
|
||||||
let statusline.=""
|
\ 'desc' : 'centered-cursor mode',
|
||||||
let statusline.="%{fugitive#head()!=''?'\ \ '.fugitive#head().'\ ':''}"
|
\ }
|
||||||
let statusline.="%3*"
|
\ ]
|
||||||
let statusline.=""
|
|
||||||
let statusline.="%4*"
|
function! s:winnr() abort
|
||||||
let statusline.="\ %<"
|
return s:MESSLETTERS.circled_num(winnr(), g:spacevim_buffer_index_type)
|
||||||
let statusline.="%f"
|
|
||||||
let statusline.="%{&modified?'\ \ +':''}"
|
|
||||||
let statusline.="%{&readonly?'\ \ ':''}"
|
|
||||||
let statusline.="%="
|
|
||||||
let statusline.="\ %{''!=#&filetype?&filetype:'none'}"
|
|
||||||
let statusline.="%(\ %{(&bomb\|\|'^$\|utf-8'!~#&fileencoding?'\ '.&fileencoding.(&bomb?'-bom':''):'').('unix'!=#&fileformat?'\ '.&fileformat:'')}%)"
|
|
||||||
let statusline.="%(\ \ %{&modifiable?(&expandtab?'et\ ':'noet\ ').&shiftwidth:''}%)"
|
|
||||||
let statusline.="%3*"
|
|
||||||
let statusline.="\ "
|
|
||||||
let statusline.="%2*"
|
|
||||||
let statusline.=""
|
|
||||||
let statusline.="%1*"
|
|
||||||
let statusline.="\ %2v"
|
|
||||||
let statusline.="\ %3p%%\ "
|
|
||||||
return statusline
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! InactiveStatus()
|
function! s:filename() abort
|
||||||
let statusline=""
|
return (&modified ? ' * ' : ' - ') . s:filesize() . fnamemodify(bufname('%'), ':t')
|
||||||
let statusline.="%(%{'help'!=&filetype?'\ \ '.bufnr('%').'\ \ ':'\ '}%)"
|
|
||||||
let statusline.="%{fugitive#head()!=''?'\ \ '.fugitive#head().'\ ':'\ '}"
|
|
||||||
let statusline.="\ %<"
|
|
||||||
let statusline.="%f"
|
|
||||||
let statusline.="%{&modified?'\ \ +':''}"
|
|
||||||
let statusline.="%{&readonly?'\ \ ':''}"
|
|
||||||
let statusline.="%="
|
|
||||||
let statusline.="\ %{''!=#&filetype?&filetype:'none'}"
|
|
||||||
let statusline.="%(\ %{(&bomb\|\|'^$\|utf-8'!~#&fileencoding?'\ '.&fileencoding.(&bomb?'-bom':''):'').('unix'!=#&fileformat?'\ '.&fileformat:'')}%)"
|
|
||||||
let statusline.="%(\ \ %{&modifiable?(&expandtab?'et\ ':'noet\ ').&shiftwidth:''}%)"
|
|
||||||
let statusline.="\ \ "
|
|
||||||
let statusline.="\ %2v"
|
|
||||||
let statusline.="\ %3p%%\ "
|
|
||||||
return statusline
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:git_branch() abort
|
||||||
|
if exists('g:loaded_fugitive')
|
||||||
|
let l:head = fugitive#head()
|
||||||
|
return empty(l:head) ? '' : ''.l:head . ' '
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:modes() abort
|
||||||
|
let m = '❖ '
|
||||||
|
for mode in s:loaded_modes
|
||||||
|
let m .= mode . ' '
|
||||||
|
endfor
|
||||||
|
return m
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:filesize() abort
|
||||||
|
let l:size = getfsize(bufname('%'))
|
||||||
|
if l:size == 0 || l:size == -1 || l:size == -2
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
if l:size < 1024
|
||||||
|
return l:size.' bytes '
|
||||||
|
elseif l:size < 1024*1024
|
||||||
|
return printf('%.1f', l:size/1024.0).'k '
|
||||||
|
elseif l:size < 1024*1024*1024
|
||||||
|
return printf('%.1f', l:size/1024.0/1024.0) . 'm '
|
||||||
|
else
|
||||||
|
return printf('%.1f', l:size/1024.0/1024.0/1024.0) . 'g '
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#layers#core#statusline#get(...) abort
|
||||||
|
if a:0 > 0
|
||||||
|
return s:active()
|
||||||
|
else
|
||||||
|
return s:inactive()
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:active() abort
|
||||||
|
let l:m_r_f = '%7* %m%r%y %*'
|
||||||
|
let l:ff = '%8* %{&ff} |'
|
||||||
|
let l:enc = " %{''.(&fenc!=''?&fenc:&enc).''} | %{(&bomb?\",BOM\":\"\")}"
|
||||||
|
let l:pos = '%l:%c%V %*'
|
||||||
|
let l:pct = '%9* %P %*'
|
||||||
|
return '%#SpaceVim_statusline_a# ' . s:winnr() . ' %#SpaceVim_statusline_a_b#'
|
||||||
|
\ . '%#SpaceVim_statusline_b# ' . s:filename() . ' %#SpaceVim_statusline_b_c#'
|
||||||
|
\ . '%#SpaceVim_statusline_c# ' . &filetype . ' %#SpaceVim_statusline_c_b#'
|
||||||
|
\ . '%#SpaceVim_statusline_b# ' . s:modes() . ' %#SpaceVim_statusline_b_c#'
|
||||||
|
\ . '%#SpaceVim_statusline_c# ' . s:git_branch() . ' %#SpaceVim_statusline_c_b#'
|
||||||
|
\ . '%#SpaceVim_statusline_b# %='
|
||||||
|
\ . '%#SpaceVim_statusline_c_b#%#SpaceVim_statusline_c#%{" " . &ff . "|" . (&fenc!=""?&fenc:&enc) . " "}'
|
||||||
|
\ . '%#SpaceVim_statusline_b_c#%#SpaceVim_statusline_b# %P '
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:inactive() abort
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
function! s:gitgutter()
|
||||||
|
if exists('b:gitgutter_summary')
|
||||||
|
let l:summary = get(b:, 'gitgutter_summary')
|
||||||
|
if l:summary[0] != 0 || l:summary[1] != 0 || l:summary[2] != 0
|
||||||
|
return ' +'.l:summary[0].' ~'.l:summary[1].' -'.l:summary[2].' '
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#core#statusline#init() abort
|
function! SpaceVim#layers#core#statusline#init() abort
|
||||||
augroup status
|
augroup status
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd WinEnter * setlocal statusline=%!ActiveStatus()
|
autocmd WinEnter * setlocal statusline=%!SpaceVim#layers#core#statusline#get(1)
|
||||||
autocmd WinLeave * setlocal statusline=%!InactiveStatus()
|
autocmd WinLeave * setlocal statusline=%!SpaceVim#layers#core#statusline#get()
|
||||||
autocmd ColorScheme kalisi if(&background=="dark") | hi User1 guibg=#afd700 guifg=#005f00 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="dark") | hi User2 guibg=#005f00 guifg=#afd700 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="dark") | hi User3 guibg=#222222 guifg=#005f00 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="dark") | hi User4 guibg=#222222 guifg=#d0d0d0 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="light") | hi User1 guibg=#afd700 guifg=#005f00 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="light") | hi User2 guibg=#005f00 guifg=#afd700 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="light") | hi User3 guibg=#707070 guifg=#005f00 | endif
|
|
||||||
autocmd ColorScheme kalisi if(&background=="light") | hi User4 guibg=#707070 guifg=#d0d0d0 | endif
|
|
||||||
augroup END
|
augroup END
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#layers#core#statusline#def_colors() abort
|
||||||
|
hi! SpaceVim_statusline_a ctermbg=003 ctermfg=Black guibg=#a89984 guifg=#282828
|
||||||
|
hi! SpaceVim_statusline_a_b ctermbg=003 ctermfg=Black guibg=#504945 guifg=#a89984
|
||||||
|
hi! SpaceVim_statusline_b ctermbg=003 ctermfg=Black guibg=#504945 guifg=#a89984
|
||||||
|
hi! SpaceVim_statusline_b_c ctermbg=003 ctermfg=Black guibg=#3c3836 guifg=#504945
|
||||||
|
hi! SpaceVim_statusline_c ctermbg=003 ctermfg=Black guibg=#3c3836 guifg=#a89984
|
||||||
|
hi! SpaceVim_statusline_c_b ctermbg=003 ctermfg=Black guibg=#504945 guifg=#3c3836
|
||||||
|
endfunction
|
||||||
|
@ -188,7 +188,9 @@ endfunction
|
|||||||
function! zvim#util#OpenVimfiler() abort
|
function! zvim#util#OpenVimfiler() abort
|
||||||
if bufnr('vimfiler') == -1
|
if bufnr('vimfiler') == -1
|
||||||
VimFiler
|
VimFiler
|
||||||
AirlineRefresh
|
if exists(':AirlineRefresh')
|
||||||
|
AirlineRefresh
|
||||||
|
endif
|
||||||
wincmd p
|
wincmd p
|
||||||
if &filetype !=# 'startify'
|
if &filetype !=# 'startify'
|
||||||
IndentLinesToggle
|
IndentLinesToggle
|
||||||
@ -197,7 +199,9 @@ function! zvim#util#OpenVimfiler() abort
|
|||||||
wincmd p
|
wincmd p
|
||||||
else
|
else
|
||||||
VimFiler
|
VimFiler
|
||||||
AirlineRefresh
|
if exists(':AirlineRefresh')
|
||||||
|
AirlineRefresh
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ title: "Documentation"
|
|||||||
* [Font](#font)
|
* [Font](#font)
|
||||||
* [UI Toggles](#ui-toggles)
|
* [UI Toggles](#ui-toggles)
|
||||||
* [Statusline && tabline](#statusline--tabline)
|
* [Statusline && tabline](#statusline--tabline)
|
||||||
|
* [statusline](#statusline)
|
||||||
* [Manual](#manual)
|
* [Manual](#manual)
|
||||||
* [Completion](#completion)
|
* [Completion](#completion)
|
||||||
* [Unite/Denite](#unitedenite)
|
* [Unite/Denite](#unitedenite)
|
||||||
@ -326,9 +327,23 @@ The statusline and tabline is a heavily customized [airline](https://github.com/
|
|||||||
- checker info: numbers of errors and warnings.
|
- checker info: numbers of errors and warnings.
|
||||||
- trailing line number.
|
- trailing line number.
|
||||||
|
|
||||||
Key Binding | Description
|
Key Binding | Description
|
||||||
----------- | -----------
|
----------- | -----------
|
||||||
`SPC [1-9]` | jump to the index of tabline.
|
`SPC [1-9]` | jump to the index of tabline.
|
||||||
|
|
||||||
|
#### statusline
|
||||||
|
|
||||||
|
The `core#statusline` layer provide a heavily customized powerline with the following capabilities:, It is inspired by spacemacs's mode-line.
|
||||||
|
|
||||||
|
|
||||||
|
- show the window number
|
||||||
|
- color code for current state
|
||||||
|
- show the number of search occurrences via anzu
|
||||||
|
- toggle flycheck info
|
||||||
|
- toggle battery info
|
||||||
|
- toggle minor mode lighters
|
||||||
|
|
||||||
|
Reminder of the color codes for the states:
|
||||||
|
|
||||||
|
|
||||||
## Manual
|
## Manual
|
||||||
|
Loading…
Reference in New Issue
Block a user