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,6 +55,9 @@ let s:VERSION = '5.0.2'
let s:heartbeats_buffer = [] let s:heartbeats_buffer = []
let s:last_sent = localtime() let s:last_sent = localtime()
function! s:Init()
" For backwards compatibility, rename wakatime.conf to wakatime.cfg " For backwards compatibility, rename wakatime.conf to wakatime.cfg
if !filereadable(s:config_file) if !filereadable(s:config_file)
if filereadable(expand("$HOME/.wakatime")) if filereadable(expand("$HOME/.wakatime"))
@ -79,11 +82,27 @@ let s:VERSION = '5.0.2'
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
let s:redraw_setting = 'enabled'
endif 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 endif
else
redraw!
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()
" }}} " }}}