Skip to content

Commit

Permalink
Add unavailable option
Browse files Browse the repository at this point in the history
  • Loading branch information
sainnhe committed Mar 7, 2024
1 parent a861f69 commit 1e8de96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,30 @@ let g:lightline.component_expand = {
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ 'linter_unavailable': 'lightline#ale#unavailable',
\ }
```

2. Set color to the components:

```viml
let g:lightline.component_type = {
\ 'linter_checking': 'right',
\ 'linter_infos': 'right',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'right',
\ }
```

3. Add the components to the lightline, for example to the right side:

```viml
let g:lightline.active = { 'right': [[ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ]] }
let g:lightline.active = { 'right': [[ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok', 'linter_unavailable' ]] }
```

3.1. Lineinfo, fileformat, etc. have to be added additionaly. Final example:

```viml
let g:lightline.active = {
\ 'right': [ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
\ 'right': [ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok', 'linter_unavailable' ],
\ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype'] ] }
Expand Down Expand Up @@ -88,6 +86,10 @@ The indicator to use when there are errors. Default is `E:`.

The indicator to use when there are no warnings or errors. Default is `OK`.

##### `g:lightline#ale#indicator_unavailable`

The indicator to use when there are no warnings or errors. Default is an empty string.

### Using icons as indicators

If you would like to replace the default indicators with symbols like on the screenshot, then you'll need to ensure you have some "iconic fonts" installed, such as [Font Awesome](https://fontawesome.com). A common alternative is to replace your primary font with one of the [Patched Nerd Fonts](https://github.com/ryanoasis/nerd-fonts), which saves you from having to install multiple fonts.
Expand Down Expand Up @@ -115,6 +117,7 @@ let g:lightline#ale#indicator_infos = "\uf129"
let g:lightline#ale#indicator_warnings = "\uf071"
let g:lightline#ale#indicator_errors = "\uf05e"
let g:lightline#ale#indicator_ok = "\uf00c"
let g:lightline#ale#indicator_unavailable = "\uf05e"
```

## License
Expand Down
8 changes: 8 additions & 0 deletions autoload/lightline/ale.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let s:indicator_warnings = get(g:, 'lightline#ale#indicator_warnings', 'W: ')
let s:indicator_errors = get(g:, 'lightline#ale#indicator_errors', 'E: ')
let s:indicator_ok = get(g:, 'lightline#ale#indicator_ok', 'OK')
let s:indicator_checking = get(g:, 'lightline#ale#indicator_checking', 'Linting...')
let s:indicator_unavailable = get(g:, 'lightline#ale#indicator_unavailable', '')


""""""""""""""""""""""
Expand Down Expand Up @@ -46,6 +47,13 @@ function! lightline#ale#checking() abort
return ale#engine#IsCheckingBuffer(bufnr('')) ? s:indicator_checking : ''
endfunction

function! lightline#ale#unavailable() abort
if !lightline#ale#linted()
return s:indicator_unavailable
else
return ''
endif
endfunction

""""""""""""""""""
" Helper functions
Expand Down

0 comments on commit 1e8de96

Please sign in to comment.