From 558c5ec87b00c3a4375695af1f84d3f21a53faf5 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 16 Nov 2020 19:08:31 -0500 Subject: [PATCH] Show lower precision blocks on Windows. The high precision block characters do not display properly. --- autoload/startuptime.vim | 10 +++++++++- doc/startuptime.txt | 7 +++++++ doc/tags | 2 ++ plugin/startuptime.vim | 27 +++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/autoload/startuptime.vim b/autoload/startuptime.vim index 3a92ceb..831d03e 100644 --- a/autoload/startuptime.vim +++ b/autoload/startuptime.vim @@ -419,13 +419,21 @@ function! s:ConstrainPattern(pattern, lines, columns) endfunction function! s:CreatePlotLine(size, max, width) - if has('multi_byte') && &encoding ==# 'utf-8' + if g:startuptime_use_blocks let l:block_chars = { \ 1: nr2char(0x258F), 2: nr2char(0x258E), \ 3: nr2char(0x258D), 4: nr2char(0x258C), \ 5: nr2char(0x258B), 6: nr2char(0x258A), \ 7: nr2char(0x2589), 8: nr2char(0x2588) \ } + if !g:startuptime_fine_blocks + let l:block_chars[1] = '' + let l:block_chars[2] = '' + let l:block_chars[3] = l:block_chars[4] + let l:block_chars[5] = l:block_chars[4] + let l:block_chars[6] = l:block_chars[8] + let l:block_chars[7] = l:block_chars[8] + endif let l:width = 0.0 + a:width * a:size / a:max let l:plot = repeat(l:block_chars[8], float2nr(l:width)) let l:remainder = s:Max([0.0, l:width - float2nr(l:width)]) diff --git a/doc/startuptime.txt b/doc/startuptime.txt index 9da963a..ad95c4e 100644 --- a/doc/startuptime.txt +++ b/doc/startuptime.txt @@ -127,6 +127,13 @@ than these options. *g:startuptime_colorize* `1` Specifies whether table data is colorized +*g:startuptime_use_blocks* `1` if 'encoding' is set to "utf-8" + Specifies whether Unicode block and `0` otherwise + elements are used for plotting +*g:startuptime_fine_blocks* `0` on Windows and `1` otherwise + Specifies whether 1/8 increments + are used for Unicode blocks (1/2 + increments are used otherwise) The variables can be customized in your |.vimrc|, as shown in the following example. diff --git a/doc/tags b/doc/tags index 9297b5f..93b8f49 100644 --- a/doc/tags +++ b/doc/tags @@ -3,6 +3,7 @@ g:startuptime_colorize startuptime.txt /*g:startuptime_colorize* g:startuptime_event_width startuptime.txt /*g:startuptime_event_width* g:startuptime_exe_args startuptime.txt /*g:startuptime_exe_args* g:startuptime_exe_path startuptime.txt /*g:startuptime_exe_path* +g:startuptime_fine_blocks startuptime.txt /*g:startuptime_fine_blocks* g:startuptime_more_info_key_seq startuptime.txt /*g:startuptime_more_info_key_seq* g:startuptime_other_events startuptime.txt /*g:startuptime_other_events* g:startuptime_percent_width startuptime.txt /*g:startuptime_percent_width* @@ -13,6 +14,7 @@ g:startuptime_sourcing_events startuptime.txt /*g:startuptime_sourcing_events* g:startuptime_split_edit_key_seq startuptime.txt /*g:startuptime_split_edit_key_seq* g:startuptime_time_width startuptime.txt /*g:startuptime_time_width* g:startuptime_tries startuptime.txt /*g:startuptime_tries* +g:startuptime_use_blocks startuptime.txt /*g:startuptime_use_blocks* startuptime-arguments startuptime.txt /*startuptime-arguments* startuptime-color-customization startuptime.txt /*startuptime-color-customization* startuptime-configuration startuptime.txt /*startuptime-configuration* diff --git a/plugin/startuptime.vim b/plugin/startuptime.vim index a22dd4d..5cc5eec 100644 --- a/plugin/startuptime.vim +++ b/plugin/startuptime.vim @@ -15,6 +15,22 @@ endif " * User Configuration " ************************************************* +function! s:OnWsl() + " Recent versions of neovim provide a 'wsl' pseudo-feature. + if has('wsl') | return 1 | endif + if has('unix') && executable('uname') + let l:uname = system('uname -a') + if stridx(l:uname, 'Microsoft') ># -1 + return 1 + endif + endif + return 0 +endfunction + +" ************************************************* +" * User Configuration +" ************************************************* + let g:startuptime_more_info_key_seq = \ get(g:, 'startuptime_more_info_key_seq', 'K') let g:startuptime_split_edit_key_seq = @@ -43,6 +59,17 @@ let g:startuptime_plot_width = let g:startuptime_colorize = \ get(g:, 'startuptime_colorize', 1) +let s:use_blocks = has('multi_byte') && &g:encoding ==# 'utf-8' +let g:startuptime_use_blocks = + \ get(g:, 'startuptime_use_blocks', s:use_blocks) +" The built-in Windows terminal emulator (used for CMD, Powershell, and WSL) +" does not properly display some block characters (i.e., the 1/8 precision +" blocks) using the default font, Consolas. The characters display properly on +" Cygwin using its default font, Lucida Console, and also when using Consolas. +let s:win_term = has('win32') || s:OnWsl() +let g:startuptime_fine_blocks = + \ get(g:, 'startuptime_fine_blocks', !s:win_term) + " The default highlight groups (for colors) are specified below. " Change these default colors by defining or linking the corresponding " highlight groups.