diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc21723..bdf50b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,12 @@ This is the Changelog for the vim-airline project. - [battery.vim](https://github.com/lambdalisue/battery.vim) support - [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) support - [gen_tags.vim](https://github.com/jsfaint/gen_tags.vim) support + - Ascii Scrollbar support - Improvements - git branch can also be displayed using [gina.vim](https://github.com/lambdalisue/gina.vim) - coc extensions can also show additional status messages as well as the current function - [coc-git](https://github.com/neoclide/coc-git) extension integrated into hunks extension + - rewrote parts using Vim9 Script for performance improvements - Other - Changed CI from travis-ci.org to GitHub Actions - Introduce Vim script static analysis using [reviewdog](https://github.com/reviewdog/action-vint) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 71a2d64f..82dd02ac 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -262,6 +262,11 @@ function! airline#extensions#load() call add(s:loaded_ext, 'bookmark') endif + if get(g:, 'airline#extensions#scrollbar#enabled', 1) + call airline#extensions#scrollbar#init(s:ext) + call add(s:loaded_ext, 'scrollbar') + endif + if get(g:, 'airline#extensions#csv#enabled', 1) \ && (get(g:, 'loaded_csv', 0) || exists(':Table')) call airline#extensions#csv#init(s:ext) diff --git a/autoload/airline/extensions/scrollbar.vim b/autoload/airline/extensions/scrollbar.vim new file mode 100644 index 00000000..6f6afd3b --- /dev/null +++ b/autoload/airline/extensions/scrollbar.vim @@ -0,0 +1,36 @@ +" MIT License. Copyright (c) 2013-2021 +" vim: et ts=2 sts=2 sw=2 et + +scriptencoding utf-8 + +function! airline#extensions#scrollbar#calculate() abort + if winwidth(0) > 200 && get(w:, 'airline_active', 0) + let overwrite = 0 + if &encoding ==? 'utf-8' && !get(g:, 'airline_symbols_ascii', 0) + let [left, right, middle] = [ '|', '|', '█'] + let overwrite = 1 + else + let [left, right, middle] = [ '[', ']', '-'] + endif + let spc = get(g:, 'airline_symbols.space', ' ') + let width = 20 " max width, plus one border and indicator + let perc = (line('.') + 0.0) / (line('$') + 0.0) + let before = float2nr(round(perc * width)) + if before > 0 && line('.') == 1 + let before = 0 + let left = (overwrite ? '' : left) + endif + let after = width - before + if (after <= 1 && line('.') == line('$')) + let after = 0 + let right = (overwrite ? '' : right) + endif + return left . repeat(spc, before) . middle . repeat(spc, (width-before)) . right + else + return '' + endif +endfunction + +function! airline#extensions#scrollbar#init(ext) abort + call airline#parts#define_function('scrollbar', 'airline#extensions#scrollbar#calculate') +endfunction diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 9b3e14c1..88603364 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -186,10 +186,11 @@ function! airline#init#bootstrap() \ 'syntastic-err', 'eclim', 'whitespace','windowswap', \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count', \ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count', - \ 'lsp_error_count', 'lsp_warning_count', + \ 'lsp_error_count', 'lsp_warning_count', 'scrollbar', \ 'nvimlsp_error_count', 'nvimlsp_warning_count', \ 'languageclient_error_count', 'languageclient_warning_count', \ 'coc_warning_count', 'coc_error_count', 'vista', 'battery']) + call airline#parts#define_text('bookmark', '') call airline#parts#define_text('capslock', '') call airline#parts#define_text('gutentags', '') @@ -225,7 +226,7 @@ function! airline#init#sections() let g:airline_section_gutter = airline#section#create(['%=']) endif if !exists('g:airline_section_x') - let g:airline_section_x = airline#section#create_right(['coc_current_function', 'bookmark', 'tagbar', 'vista', 'gutentags', 'gen_tags', 'omnisharp', 'grepper', 'filetype']) + let g:airline_section_x = airline#section#create_right(['coc_current_function', 'bookmark', 'scrollbar', 'tagbar', 'vista', 'gutentags', 'gen_tags', 'omnisharp', 'grepper', 'filetype']) endif if !exists('g:airline_section_y') let g:airline_section_y = airline#section#create_right(['ffenc']) diff --git a/doc/airline.txt b/doc/airline.txt index b5b1a34a..3654ab10 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -1355,6 +1355,12 @@ groups: airline_tabhid: hidden buffer airline_tabhid_right: idem, but on the right +------------------------------------- *airline-scrollbar* + +Displays an Ascii Scrollbar for active windows with a width > 200. + +* enable/disable scrollbar integration > + let g:airline#extensions#scrollbar#enabled = 1 (default: 1) ------------------------------------- *airline-taboo* taboo.vim