mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 05:20:04 +08:00
Add time battery status sections
This commit is contained in:
parent
65c6493026
commit
072c8ede5e
11
autoload/SpaceVim/api/time.vim
Normal file
11
autoload/SpaceVim/api/time.vim
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
let s:self = {}
|
||||||
|
|
||||||
|
" see: man 3 strftime
|
||||||
|
function! s:self.current_time() abort
|
||||||
|
return strftime('%I:%M %p')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! SpaceVim#api#time#get() abort
|
||||||
|
return deepcopy(s:self)
|
||||||
|
endfunction
|
@ -3,6 +3,7 @@ scriptencoding utf-8
|
|||||||
let g:_spacevim_statusline_loaded = 1
|
let g:_spacevim_statusline_loaded = 1
|
||||||
" APIs
|
" APIs
|
||||||
let s:MESSLETTERS = SpaceVim#api#import('messletters')
|
let s:MESSLETTERS = SpaceVim#api#import('messletters')
|
||||||
|
let s:TIME = SpaceVim#api#import('time')
|
||||||
|
|
||||||
" init
|
" init
|
||||||
let s:loaded_modes = ['center-cursor']
|
let s:loaded_modes = ['center-cursor']
|
||||||
@ -21,6 +22,24 @@ let s:modes = {
|
|||||||
\ },
|
\ },
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
|
let s:loaded_sections = []
|
||||||
|
|
||||||
|
function! s:battery_status() abort
|
||||||
|
if executable('acpi')
|
||||||
|
return substitute(split(system('acpi'))[-1], '%', '%%', 'g')
|
||||||
|
else
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:time() abort
|
||||||
|
return s:TIME.current_time()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:sections = {
|
||||||
|
\ 'battery status' : function('s:battery_status'),
|
||||||
|
\ }
|
||||||
|
|
||||||
function! s:winnr() abort
|
function! s:winnr() abort
|
||||||
return s:MESSLETTERS.circled_num(winnr(), g:spacevim_buffer_index_type)
|
return s:MESSLETTERS.circled_num(winnr(), g:spacevim_buffer_index_type)
|
||||||
endfunction
|
endfunction
|
||||||
@ -37,6 +56,7 @@ function! s:git_branch() abort
|
|||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:modes() abort
|
function! s:modes() abort
|
||||||
let m = '❖ '
|
let m = '❖ '
|
||||||
for mode in s:loaded_modes
|
for mode in s:loaded_modes
|
||||||
@ -77,15 +97,23 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:active() abort
|
function! s:active() abort
|
||||||
return '%#SpaceVim_statusline_a# ' . s:winnr() . ' %#SpaceVim_statusline_a_b#'
|
let l = '%#SpaceVim_statusline_a# ' . s:winnr() . ' %#SpaceVim_statusline_a_b#'
|
||||||
\ . '%#SpaceVim_statusline_b# ' . s:filename() . ' %#SpaceVim_statusline_b_c#'
|
\ . '%#SpaceVim_statusline_b# ' . s:filename() . ' %#SpaceVim_statusline_b_c#'
|
||||||
\ . '%#SpaceVim_statusline_c# ' . &filetype . ' %#SpaceVim_statusline_c_b#'
|
\ . '%#SpaceVim_statusline_c# ' . &filetype . ' %#SpaceVim_statusline_c_b#'
|
||||||
\ . '%#SpaceVim_statusline_b# ' . s:modes() . ' %#SpaceVim_statusline_b_c#'
|
\ . '%#SpaceVim_statusline_b# ' . s:modes() . ' %#SpaceVim_statusline_b_c#'
|
||||||
\ . '%#SpaceVim_statusline_c# ' . s:git_branch() . ' %#SpaceVim_statusline_c_b#'
|
\ . '%#SpaceVim_statusline_c# ' . s:git_branch() . ' %#SpaceVim_statusline_c_z#'
|
||||||
\ . '%#SpaceVim_statusline_b# %='
|
\ . '%#SpaceVim_statusline_z#%='
|
||||||
\ . '%#SpaceVim_statusline_c_b#%#SpaceVim_statusline_c#%{" " . &ff . "|" . (&fenc!=""?&fenc:&enc) . " "}'
|
if index(s:loaded_sections, 'battery status') != -1
|
||||||
|
let l .= '%#SpaceVim_statusline_z_b#%#SpaceVim_statusline_b# ' . s:battery_status() . ' %#SpaceVim_statusline_c_b#'
|
||||||
|
else
|
||||||
|
let l .= '%#SpaceVim_statusline_c_z#'
|
||||||
|
endif
|
||||||
|
let l .= '%#SpaceVim_statusline_c#%{" " . &ff . "|" . (&fenc!=""?&fenc:&enc) . " "}'
|
||||||
\ . '%#SpaceVim_statusline_b_c#%#SpaceVim_statusline_b# %P '
|
\ . '%#SpaceVim_statusline_b_c#%#SpaceVim_statusline_b# %P '
|
||||||
|
if index(s:loaded_sections, 'time') != -1
|
||||||
|
let l .= '%#SpaceVim_statusline_c_b#%#SpaceVim_statusline_c# ' . s:time() . ' '
|
||||||
|
endif
|
||||||
|
return l
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:inactive() abort
|
function! s:inactive() abort
|
||||||
@ -123,6 +151,11 @@ function! SpaceVim#layers#core#statusline#def_colors() abort
|
|||||||
hi! SpaceVim_statusline_b_c ctermbg=003 ctermfg=Black guibg=#3c3836 guifg=#504945
|
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 ctermbg=003 ctermfg=Black guibg=#3c3836 guifg=#a89984
|
||||||
hi! SpaceVim_statusline_c_b ctermbg=003 ctermfg=Black guibg=#504945 guifg=#3c3836
|
hi! SpaceVim_statusline_c_b ctermbg=003 ctermfg=Black guibg=#504945 guifg=#3c3836
|
||||||
|
hi! SpaceVim_statusline_c_z ctermbg=003 ctermfg=Black guibg=#665c54 guifg=#3c3836
|
||||||
|
hi! SpaceVim_statusline_z_c ctermbg=003 ctermfg=Black guibg=#3c3836 guifg=#665c54
|
||||||
|
hi! SpaceVim_statusline_z_b ctermbg=003 ctermfg=Black guibg=#665c54 guifg=#504945
|
||||||
|
hi! SpaceVim_statusline_z ctermbg=003 ctermfg=Black guibg=#665c54 guifg=#665c54
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#core#statusline#toggle_mode(name) abort
|
function! SpaceVim#layers#core#statusline#toggle_mode(name) abort
|
||||||
@ -134,6 +167,22 @@ function! SpaceVim#layers#core#statusline#toggle_mode(name) abort
|
|||||||
let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#layers#core#statusline#toggle_section(name) abort
|
||||||
|
if index(s:loaded_sections, a:name) != -1
|
||||||
|
call remove(s:loaded_sections, index(s:loaded_sections, a:name))
|
||||||
|
else
|
||||||
|
call add(s:loaded_sections, a:name)
|
||||||
|
endif
|
||||||
|
let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! Test() abort
|
function! Test() abort
|
||||||
echo s:loaded_modes
|
echo s:loaded_modes
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#layers#core#statusline#config() abort
|
||||||
|
call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 'b'], 'call SpaceVim#layers#core#statusline#toggle_section("battery status")',
|
||||||
|
\ 'toggle the battery status', 1)
|
||||||
|
call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 't'], 'call SpaceVim#layers#core#statusline#toggle_section("time")',
|
||||||
|
\ 'toggle the time', 1)
|
||||||
|
endfunction
|
||||||
|
@ -10,6 +10,7 @@ endfunction
|
|||||||
|
|
||||||
function! SpaceVim#layers#lang#markdown#config() abort
|
function! SpaceVim#layers#lang#markdown#config() abort
|
||||||
let g:markdown_minlines = 100
|
let g:markdown_minlines = 100
|
||||||
|
let g:markdown_syntax_conceal = 0
|
||||||
let g:markdown_enable_mappings = 0
|
let g:markdown_enable_mappings = 0
|
||||||
let g:markdown_enable_insert_mode_leader_mappings = 0
|
let g:markdown_enable_insert_mode_leader_mappings = 0
|
||||||
let g:markdown_enable_spell_checking = 0
|
let g:markdown_enable_spell_checking = 0
|
||||||
|
@ -9,6 +9,7 @@ function! SpaceVim#mapping#space#init() abort
|
|||||||
let g:_spacevim_mappings_space['?'] = ['Unite menu:CustomKeyMaps -input=[SPC]', 'show mappings']
|
let g:_spacevim_mappings_space['?'] = ['Unite menu:CustomKeyMaps -input=[SPC]', 'show mappings']
|
||||||
let g:_spacevim_mappings_space.t = {'name' : '+Toggles'}
|
let g:_spacevim_mappings_space.t = {'name' : '+Toggles'}
|
||||||
let g:_spacevim_mappings_space.t.h = {'name' : '+Toggles highlight'}
|
let g:_spacevim_mappings_space.t.h = {'name' : '+Toggles highlight'}
|
||||||
|
let g:_spacevim_mappings_space.t.m = {'name' : '+modeline'}
|
||||||
let g:_spacevim_mappings_space.T = {'name' : '+UI toggles/themes'}
|
let g:_spacevim_mappings_space.T = {'name' : '+UI toggles/themes'}
|
||||||
let g:_spacevim_mappings_space.a = {'name' : '+Applications'}
|
let g:_spacevim_mappings_space.a = {'name' : '+Applications'}
|
||||||
let g:_spacevim_mappings_space.b = {'name' : '+Buffers'}
|
let g:_spacevim_mappings_space.b = {'name' : '+Buffers'}
|
||||||
@ -86,7 +87,7 @@ function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:has_map_to_spc() abort
|
function! s:has_map_to_spc() abort
|
||||||
return get(g:, 'mapleader', '\') == ' '
|
return get(g:, 'mapleader', '\') ==# ' '
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:windows_layout_toggle() abort
|
function! s:windows_layout_toggle() abort
|
||||||
|
@ -338,13 +338,46 @@ The `core#statusline` layer provide a heavily customized powerline with the foll
|
|||||||
|
|
||||||
- show the window number
|
- show the window number
|
||||||
- color code for current state
|
- color code for current state
|
||||||
- show the number of search occurrences via anzu
|
- show the number of search results
|
||||||
- toggle flycheck info
|
- toggle syntax checking info
|
||||||
- toggle battery info
|
- toggle battery info
|
||||||
- toggle minor mode lighters
|
- toggle minor mode lighters
|
||||||
|
|
||||||
Reminder of the color codes for the states:
|
Reminder of the color codes for the states:
|
||||||
|
|
||||||
|
Mode | Color
|
||||||
|
--- | ---
|
||||||
|
Normal | Orange
|
||||||
|
Insert | Green
|
||||||
|
Visual | Grey
|
||||||
|
|
||||||
|
all the colors based on the current colorscheme
|
||||||
|
|
||||||
|
Some elements can be dynamically toggled:
|
||||||
|
|
||||||
|
Key Binding | Description
|
||||||
|
----------- | -----------
|
||||||
|
`SPC t m b` | toggle the battery status (need to install acpi)
|
||||||
|
`SPC t m c` | toggle the org task clock (available in org layer)
|
||||||
|
`SPC t m m` | toggle the minor mode lighters
|
||||||
|
`SPC t m M` | toggle the major mode
|
||||||
|
`SPC t m n` | toggle the cat! (if colors layer is declared in your dotfile)
|
||||||
|
`SPC t m p` | toggle the point character position
|
||||||
|
`SPC t m t` | toggle the time
|
||||||
|
`SPC t m T` | toggle the mode line itself
|
||||||
|
`SPC t m v` | toggle the version control info
|
||||||
|
|
||||||
|
**Battery status integration:**
|
||||||
|
|
||||||
|
__acpi__ displays the percentage of total charge of the battery as well as the time remaining to charge or discharge completely the battery.
|
||||||
|
|
||||||
|
A color code is used for the battery status:
|
||||||
|
|
||||||
|
Battery State | Color
|
||||||
|
------------ | ----
|
||||||
|
Charging | Green
|
||||||
|
Discharging | Orange
|
||||||
|
Critical | Red
|
||||||
|
|
||||||
## Manual
|
## Manual
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user