new redraw setting auto, to redraw screen when command takes too long

This commit is contained in:
Alan Hamlett 2017-09-04 10:13:34 -07:00
parent a8e99ff8dc
commit d7b6f18e84
2 changed files with 79 additions and 32 deletions

View File

@ -36,7 +36,8 @@ Configuring
* `:WakaTimeApiKey` - change the api key saved in your `~/.wakatime.cfg` * `:WakaTimeApiKey` - change the api key saved in your `~/.wakatime.cfg`
* `:WakaTimeDebugEnable` - enable debug mode (may slow down Vim so disable when finished debugging) * `:WakaTimeDebugEnable` - enable debug mode (may slow down Vim so disable when finished debugging)
* `:WakaTimeDebugDisable` - disable debug mode * `:WakaTimeDebugDisable` - disable debug mode
* `:WakaTimeScreenRedrawEnable` - temporarily enable screen redraw to prevent artifacts * `:WakaTimeScreenRedrawEnable` - enable screen redraw to prevent artifacts
* `:WakaTimeScreenRedrawEnableAuto` - redraw screen when plugin takes too long
* `:WakaTimeScreenRedrawDisable` - disable screen redraw for performance * `:WakaTimeScreenRedrawDisable` - disable screen redraw for performance
#### Vimrc Settings: #### Vimrc Settings:
@ -46,12 +47,16 @@ Configuring
Tells the plugin to use a custom python binary. Tells the plugin to use a custom python binary.
The default is to use `python` from your system PATH. The default is to use `python` from your system PATH.
let g:wakatime_ScreenRedraw = 1 #### WakaTime Settings:
Add this line to your `~/.wakatime.cfg` file to modify your screen redraw setting:
vi_redraw = enabled
Enables redrawing the screen after sending heartbeats, to prevent screen artifacts in case a key was pressed while the plugin executed. Enables redrawing the screen after sending heartbeats, to prevent screen artifacts in case a key was pressed while the plugin executed.
Valid values for `vi_redraw` are `enabled`, `auto`, and `disabled`.
Other WakaTime plugins also share this `~/.wakatime.cfg` file. [See all configs...][wakatime-cli-config]
WakaTime plugins share a common config file located in your user home folder at `~/.wakatime.cfg` with [common plugin settings][wakatime-cli-config].
Troubleshooting Troubleshooting

View File

@ -55,34 +55,53 @@ let s:VERSION = '5.0.2'
let s:heartbeats_buffer = [] let s:heartbeats_buffer = []
let s:last_sent = localtime() let s:last_sent = localtime()
" For backwards compatibility, rename wakatime.conf to wakatime.cfg
if !filereadable(s:config_file) function! s:Init()
if filereadable(expand("$HOME/.wakatime"))
exec "silent !mv" expand("$HOME/.wakatime") expand("$HOME/.wakatime.conf") " For backwards compatibility, rename wakatime.conf to wakatime.cfg
endif if !filereadable(s:config_file)
if filereadable(expand("$HOME/.wakatime.conf")) if filereadable(expand("$HOME/.wakatime"))
if !filereadable(s:config_file) exec "silent !mv" expand("$HOME/.wakatime") expand("$HOME/.wakatime.conf")
let contents = ['[settings]'] + readfile(expand("$HOME/.wakatime.conf"), '') endif
call writefile(contents, s:config_file) if filereadable(expand("$HOME/.wakatime.conf"))
call delete(expand("$HOME/.wakatime.conf")) if !filereadable(s:config_file)
let contents = ['[settings]'] + readfile(expand("$HOME/.wakatime.conf"), '')
call writefile(contents, s:config_file)
call delete(expand("$HOME/.wakatime.conf"))
endif
endif endif
endif endif
endif
" Set default python binary location " Set default python binary location
if !exists("g:wakatime_PythonBinary") if !exists("g:wakatime_PythonBinary")
let g:wakatime_PythonBinary = 'python' let g:wakatime_PythonBinary = 'python'
endif endif
" Set default heartbeat frequency in minutes " Set default heartbeat frequency in minutes
if !exists("g:wakatime_HeartbeatFrequency") if !exists("g:wakatime_HeartbeatFrequency")
let g:wakatime_HeartbeatFrequency = 2 let g:wakatime_HeartbeatFrequency = 2
endif endif
" Set default screen redraw to 0 (s:false) " Get legacy g:wakatime_ScreenRedraw setting
if !exists("g:wakatime_ScreenRedraw") let s:redraw_setting = 'auto'
let g:wakatime_ScreenRedraw = s:false if exists("g:wakatime_ScreenRedraw") && g:wakatime_ScreenRedraw
endif let s:redraw_setting = 'enabled'
endif
" Get redraw setting from wakatime.cfg file
if s:GetIniSetting('settings', 'vi_redraw') != ''
if s:GetIniSetting('settings', 'vi_redraw') == 'enabled'
let s:redraw_setting = 'enabled'
endif
if s:GetIniSetting('settings', 'vi_redraw') == 'auto'
let s:redraw_setting = 'auto'
endif
if s:GetIniSetting('settings', 'vi_redraw') == 'disabled'
let s:redraw_setting = 'disabled'
endif
endif
endfunction
" }}} " }}}
@ -250,12 +269,15 @@ let s:VERSION = '5.0.2'
" as STDIN and we are forced to send heartbeats individually. " as STDIN and we are forced to send heartbeats individually.
call s:SendHeartbeats() call s:SendHeartbeats()
endif endif
call s:SendHeartbeats()
endif endif
endfunction endfunction
function! s:SendHeartbeats() function! s:SendHeartbeats()
let start_time = localtime()
if len(s:heartbeats_buffer) == 0 if len(s:heartbeats_buffer) == 0
let s:last_sent = localtime() let s:last_sent = start_time
return return
endif endif
@ -313,9 +335,18 @@ let s:VERSION = '5.0.2'
endif endif
endif endif
let s:last_sent = localtime() let s:last_sent = localtime()
if g:wakatime_ScreenRedraw
redraw! " need to repaint in case a key was pressed while sending " need to repaint in case a key was pressed while sending
if s:redraw_setting != 'disabled'
if s:redraw_setting == 'auto'
if s:last_sent - start_time > 0
redraw!
endif
else
redraw!
endif
endif endif
if s:is_debug_mode_on && stdout != '' if s:is_debug_mode_on && stdout != ''
echo '[WakaTime] Heartbeat Command: ' . s:JoinArgs(cmd) . "\n[WakaTime] Error: " . stdout echo '[WakaTime] Heartbeat Command: ' . s:JoinArgs(cmd) . "\n[WakaTime] Error: " . stdout
endif endif
@ -410,11 +441,18 @@ let s:VERSION = '5.0.2'
endfunction endfunction
function! s:EnableScreenRedraw() function! s:EnableScreenRedraw()
let g:wakatime_ScreenRedraw = s:true call s:SetIniSetting('settings', 'vi_redraw', 'enabled')
let s:redraw_setting = 'enabled'
endfunction
function! s:EnableScreenRedrawAuto()
call s:SetIniSetting('settings', 'vi_redraw', 'auto')
let s:redraw_setting = 'auto'
endfunction endfunction
function! s:DisableScreenRedraw() function! s:DisableScreenRedraw()
let g:wakatime_ScreenRedraw = s:false call s:SetIniSetting('settings', 'vi_redraw', 'disabled')
let s:redraw_setting = 'disabled'
endfunction endfunction
function! s:InitAndHandleActivity(is_write) function! s:InitAndHandleActivity(is_write)
@ -455,6 +493,9 @@ let s:VERSION = '5.0.2'
" }}} " }}}
call s:Init()
" Autocommand Events {{{ " Autocommand Events {{{
augroup Wakatime augroup Wakatime
@ -476,6 +517,7 @@ let s:VERSION = '5.0.2'
:command -nargs=0 WakaTimeDebugDisable call s:DisableDebugMode() :command -nargs=0 WakaTimeDebugDisable call s:DisableDebugMode()
:command -nargs=0 WakaTimeScreenRedrawDisable call s:DisableScreenRedraw() :command -nargs=0 WakaTimeScreenRedrawDisable call s:DisableScreenRedraw()
:command -nargs=0 WakaTimeScreenRedrawEnable call s:EnableScreenRedraw() :command -nargs=0 WakaTimeScreenRedrawEnable call s:EnableScreenRedraw()
:command -nargs=0 WakaTimeScreenRedrawEnableAuto call s:EnableScreenRedrawAuto()
" }}} " }}}