Removed combo bar, added combo colors, changed format, added Cheated() function (to revert last best score)

This commit is contained in:
əlemi 2019-11-06 22:27:35 +01:00
parent 4965743182
commit 93b1f9003f
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,6 +1,6 @@
" COMBO Counter " COMBO Counter
" Choose combo file depending on extension " Choose combo file depending on extension
if strlen(expand("%:e")) > 0 if strlen(expand("%:e")) > 0
let g:combo_file = $HOME . '/.vim/.combo/' . expand("%:e") . ".cmb" let g:combo_file = $HOME . '/.vim/.combo/' . expand("%:e") . ".cmb"
else else
let g:combo_file = $HOME . '/.vim/.combo/none.cmb' let g:combo_file = $HOME . '/.vim/.combo/none.cmb'
@ -15,7 +15,7 @@ endfor
let g:best_combo_all = max(scores) let g:best_combo_all = max(scores)
" Checking for ignored extensions " Checking for ignored extensions
let ignored = [ 'txt' ] let ignored = ['cmb']
let g:disable_combo = 0 let g:disable_combo = 0
for f in ignored for f in ignored
if expand("%:e") == f if expand("%:e") == f
@ -25,50 +25,66 @@ endfor
" If file should be ignored, just set text, else continue with script " If file should be ignored, just set text, else continue with script
if g:disable_combo if g:disable_combo
let g:airline_section_b = 'ᛥ -|-|%{g:best_combo_all}' let g:airline_section_b = airline#section#create(['[%{g:best_combo_all}] - ᛥ'])
else else
" Find best score for current filetype " Find best score for current filetype
if filereadable(g:combo_file) if filereadable(g:combo_file)
let g:best_combo = readfile(g:combo_file) let g:best_combo = readfile(g:combo_file)
let g:best_combo = g:best_combo[0] let g:best_combo = g:best_combo[0]
else else
silent !echo 0 > $HOME/.vim/.combo/%:e.cmb silent !echo 0 > $HOME/.vim/.combo/%:e.cmb
let g:best_combo = 0 let g:best_combo = 0
endif endif
let g:best_last_combo = g:best_combo " Used to revert
" Configure variables " Configure variables
let g:combo_counter = 0 " The actual combo variable let g:combo_counter = 0 " The actual combo variable
let g:timeout = 1 let g:timeout = 1
let g:emphasis = '' hi User1 ctermfg=247 ctermbg=237
let g:mult = 10 let g:status = '%1*[%{g:best_combo}] %{g:combo_counter} ᛥ%#airline_b#'
let g:status_max = '%1*[%{g:best_combo_all}|%{g:best_combo}] %{g:combo_counter} ᛥ%#airline_b#'
command ComboMaxOn let g:airline_section_b = airline#section#create([g:status_max]) | AirlineRefresh
command ComboMaxOff let g:airline_section_b = airline#section#create([g:status]) | AirlineRefresh
let g:airline_section_b = airline#section#create([g:status])
let g:last_combo = reltime() " Set current time as last combo time let g:last_combo = reltime() " Set current time as last combo time
let g:airline_section_b = 'ᛥ %{g:combo_counter}|%{g:best_combo}|%{g:best_combo_all} %{g:emphasis}'
function! UpdateCombo() function! UpdateCombo()
if reltimefloat(reltime(g:last_combo)) > g:timeout if reltimefloat(reltime(g:last_combo)) > g:timeout
call SaveCombo() call SaveCombo()
let g:combo_counter = 1 let g:combo_counter = 1
else else
let g:combo_counter +=1 let g:combo_counter +=1
endif endif
let g:emphasis = '' call UpdateColor()
let ceil = g:combo_counter / g:mult
let i = 0
while i < ceil
let g:emphasis = g:emphasis . '*'
let i+=1
endwhile
let g:last_combo = reltime() let g:last_combo = reltime()
endfunction endfunction
function! SaveCombo() function! SaveCombo() " Should check inside because it can be called on InsertLeave
if g:combo_counter > g:best_combo if g:combo_counter > g:best_combo
call writefile([g:combo_counter], g:combo_file) call writefile([g:combo_counter], g:combo_file)
let g:best_last_combo = g:best_combo
let g:best_combo = g:combo_counter let g:best_combo = g:combo_counter
endif endif
endfunction endfunction
function! UpdateColor()
autocmd TextChangedI * call UpdateCombo() " Every time the cursor moves, call combo function if g:combo_counter == 1
hi User1 ctermfg=247 ctermbg=237
elseif g:combo_counter == 10
hi User1 ctermfg=2 ctermbg=237
elseif g:combo_counter == 30
hi User1 ctermfg=6 ctermbg=237
elseif g:combo_counter == 50
hi User1 ctermfg=5 ctermbg=237
elseif g:combo_counter == 70
hi User1 ctermfg=3 ctermbg=237
elseif g:combo_counter == 100
hi User1 ctermfg=1 ctermbg=237
endif
endfunction
function! Cheated()
call writefile([g:best_last_combo], g:combo_file)
let g:best_combo = g:best_last_combo
endfunction
autocmd TextChangedI * call UpdateCombo() " Every time text is changed, call combo function
autocmd InsertLeave * call SaveCombo() autocmd InsertLeave * call SaveCombo()
" Options for Backspace Cheaters
" inoremap <BS> <C-o>:let g:combo_counter-=1<CR><BS>
endif endif