scrollbar: add an ascii scrollbar extension

This commit is contained in:
Christian Brabandt 2021-05-08 18:06:25 +02:00
parent e7eea7c6e8
commit ecac148e19
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
5 changed files with 52 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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'])

View File

@ -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 <https://github.com/gcmt/taboo.vim>