mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 22:20:06 +08:00
Update statusline layer
This commit is contained in:
parent
852d9559ab
commit
9d908e74b2
@ -125,11 +125,8 @@ function! SpaceVim#autocmds#VimEnter() abort
|
||||
endfor
|
||||
if get(g:, '_spacevim_statusline_loaded', 0) == 1
|
||||
set laststatus=2
|
||||
set statusline=%!ActiveStatus()
|
||||
hi User1 guibg=#afd700 guifg=#005f00
|
||||
hi User2 guibg=#005f00 guifg=#afd700
|
||||
hi User3 guibg=#222222 guifg=#005f00
|
||||
hi User4 guibg=#222222 guifg=#d0d0d0
|
||||
call SpaceVim#layers#core#statusline#def_colors()
|
||||
set statusline=%!SpaceVim#layers#core#statusline#get(1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -1,65 +1,109 @@
|
||||
" statusline
|
||||
scriptencoding utf-8
|
||||
let g:_spacevim_statusline_loaded = 1
|
||||
" APIs
|
||||
let s:MESSLETTERS = SpaceVim#api#import('messletters')
|
||||
|
||||
function! ActiveStatus()
|
||||
let statusline=""
|
||||
let statusline.="%1*"
|
||||
let statusline.="%(%{'help'!=&filetype?'\ \ '.bufnr('%'):''}\ %)"
|
||||
let statusline.="%2*"
|
||||
let statusline.=""
|
||||
let statusline.="%{fugitive#head()!=''?'\ \ '.fugitive#head().'\ ':''}"
|
||||
let statusline.="%3*"
|
||||
let statusline.=""
|
||||
let statusline.="%4*"
|
||||
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.="%3*"
|
||||
let statusline.="\ "
|
||||
let statusline.="%2*"
|
||||
let statusline.=""
|
||||
let statusline.="%1*"
|
||||
let statusline.="\ %2v"
|
||||
let statusline.="\ %3p%%\ "
|
||||
return statusline
|
||||
" init
|
||||
let s:loaded_modes = ['⊝']
|
||||
let s:modes = [
|
||||
\ {
|
||||
\ 'name' : '⊝',
|
||||
\ 'desc' : 'centered-cursor mode',
|
||||
\ }
|
||||
\ ]
|
||||
|
||||
function! s:winnr() abort
|
||||
return s:MESSLETTERS.circled_num(winnr(), g:spacevim_buffer_index_type)
|
||||
endfunction
|
||||
|
||||
function! InactiveStatus()
|
||||
let statusline=""
|
||||
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
|
||||
function! s:filename() abort
|
||||
return (&modified ? ' * ' : ' - ') . s:filesize() . fnamemodify(bufname('%'), ':t')
|
||||
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
|
||||
augroup status
|
||||
autocmd!
|
||||
autocmd WinEnter * setlocal statusline=%!ActiveStatus()
|
||||
autocmd WinLeave * setlocal statusline=%!InactiveStatus()
|
||||
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
|
||||
autocmd WinEnter * setlocal statusline=%!SpaceVim#layers#core#statusline#get(1)
|
||||
autocmd WinLeave * setlocal statusline=%!SpaceVim#layers#core#statusline#get()
|
||||
augroup END
|
||||
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
|
||||
if bufnr('vimfiler') == -1
|
||||
VimFiler
|
||||
AirlineRefresh
|
||||
if exists(':AirlineRefresh')
|
||||
AirlineRefresh
|
||||
endif
|
||||
wincmd p
|
||||
if &filetype !=# 'startify'
|
||||
IndentLinesToggle
|
||||
@ -197,7 +199,9 @@ function! zvim#util#OpenVimfiler() abort
|
||||
wincmd p
|
||||
else
|
||||
VimFiler
|
||||
AirlineRefresh
|
||||
if exists(':AirlineRefresh')
|
||||
AirlineRefresh
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -30,6 +30,7 @@ title: "Documentation"
|
||||
* [Font](#font)
|
||||
* [UI Toggles](#ui-toggles)
|
||||
* [Statusline && tabline](#statusline--tabline)
|
||||
* [statusline](#statusline)
|
||||
* [Manual](#manual)
|
||||
* [Completion](#completion)
|
||||
* [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.
|
||||
- trailing line number.
|
||||
|
||||
Key Binding | Description
|
||||
----------- | -----------
|
||||
`SPC [1-9]` | jump to the index of tabline.
|
||||
Key Binding | Description
|
||||
----------- | -----------
|
||||
`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
|
||||
|
Loading…
Reference in New Issue
Block a user