From 072c8ede5ed50089a6f0fdc02049b72c151b06f3 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 19 May 2017 00:09:15 +0800 Subject: [PATCH] Add time battery status sections --- autoload/SpaceVim/api/time.vim | 11 ++++ autoload/SpaceVim/layers/core/statusline.vim | 59 ++++++++++++++++++-- autoload/SpaceVim/layers/lang/markdown.vim | 1 + autoload/SpaceVim/mapping/space.vim | 3 +- docs/documentation.md | 37 +++++++++++- 5 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 autoload/SpaceVim/api/time.vim diff --git a/autoload/SpaceVim/api/time.vim b/autoload/SpaceVim/api/time.vim new file mode 100644 index 000000000..ba7d61c30 --- /dev/null +++ b/autoload/SpaceVim/api/time.vim @@ -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 diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index f62d417dc..a4764bec4 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -3,6 +3,7 @@ scriptencoding utf-8 let g:_spacevim_statusline_loaded = 1 " APIs let s:MESSLETTERS = SpaceVim#api#import('messletters') +let s:TIME = SpaceVim#api#import('time') " init 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 return s:MESSLETTERS.circled_num(winnr(), g:spacevim_buffer_index_type) endfunction @@ -37,6 +56,7 @@ function! s:git_branch() abort return '' endfunction + function! s:modes() abort let m = '❖ ' for mode in s:loaded_modes @@ -77,15 +97,23 @@ function! SpaceVim#layers#core#statusline#get(...) abort endfunction 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_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_c# ' . s:git_branch() . ' %#SpaceVim_statusline_c_z#' + \ . '%#SpaceVim_statusline_z#%=' + 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 ' - + if index(s:loaded_sections, 'time') != -1 + let l .= '%#SpaceVim_statusline_c_b#%#SpaceVim_statusline_c# ' . s:time() . ' ' + endif + return l endfunction 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_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_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 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) 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 echo s:loaded_modes 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 diff --git a/autoload/SpaceVim/layers/lang/markdown.vim b/autoload/SpaceVim/layers/lang/markdown.vim index 455b18554..d8e939f15 100644 --- a/autoload/SpaceVim/layers/lang/markdown.vim +++ b/autoload/SpaceVim/layers/lang/markdown.vim @@ -10,6 +10,7 @@ endfunction function! SpaceVim#layers#lang#markdown#config() abort let g:markdown_minlines = 100 + let g:markdown_syntax_conceal = 0 let g:markdown_enable_mappings = 0 let g:markdown_enable_insert_mode_leader_mappings = 0 let g:markdown_enable_spell_checking = 0 diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index d77bbaf5d..228018e1c 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -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.t = {'name' : '+Toggles'} 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.a = {'name' : '+Applications'} 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 function! s:has_map_to_spc() abort - return get(g:, 'mapleader', '\') == ' ' + return get(g:, 'mapleader', '\') ==# ' ' endfunction function! s:windows_layout_toggle() abort diff --git a/docs/documentation.md b/docs/documentation.md index 7df27ffab..459ba26d6 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -338,13 +338,46 @@ The `core#statusline` layer provide a heavily customized powerline with the foll - show the window number - color code for current state -- show the number of search occurrences via anzu -- toggle flycheck info +- show the number of search results +- toggle syntax checking info - toggle battery info - toggle minor mode lighters 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