Skip to content

Commit

Permalink
Show lower precision blocks on Windows.
Browse files Browse the repository at this point in the history
The high precision block characters do not display properly.
  • Loading branch information
dstein64 committed Nov 17, 2020
1 parent 0445f66 commit 558c5ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion autoload/startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
7 changes: 7 additions & 0 deletions doc/startuptime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand All @@ -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*
Expand Down
27 changes: 27 additions & 0 deletions plugin/startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 558c5ec

Please sign in to comment.