Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/m00qek/baleia.nvim

Colorize text with ANSI escape sequences (8, 16, 256 or TrueColor)
https://github.com/m00qek/baleia.nvim

clojure lua neovim neovim-plugin terminal terminal-colors

Last synced: about 2 months ago
JSON representation

Colorize text with ANSI escape sequences (8, 16, 256 or TrueColor)

Lists

README

        

baleia.nvim
===
[![Integration][integration-badge]][integration-runs]

Colorize text with ANSI escape sequences (8, 16, 256 or TrueColor)

## Install

Using [vim-plug][vim-plug]:

```vim
Plug 'm00qek/baleia.nvim', { 'tag': 'v1.4.0' }
```

Using [packer.nvim][packer]:

```lua
use { 'm00qek/baleia.nvim', tag = 'v1.4.0' }
```

## Setup

`baleia` can colorize an entire buffer or/and apply colors every time a new line
is added to it.

### Colorizing the entire buffer

The best approach is to create a command. In `vimscript`:

```vim
let s:baleia = luaeval("require('baleia').setup { }")
command! BaleiaColorize call s:baleia.once(bufnr('%'))
```

To highlight the current buffer:

```vim
:BaleiaColorize
```

## Automatically colorize when lines are added to the buffer

To automatically colorize when a new line is added use

```vim
let s:baleia = luaeval("require('baleia').setup { }")
autocmd BufWinEnter my-buffer call s:baleia.automatically(bufnr('%'))
```

where `my_buffer` is how you identify in which buffers it should run (please
read `:h autocmd`)

## Automatically colorize text added to the quickfix window

To automatically colorize text added to the quickfix use `BufReadPost`

```vim
let s:baleia = luaeval("require('baleia').setup { }")
autocmd BufReadPost quickfix setlocal modifiable
\ | silent call g:baleia.once(bufnr('%'))
\ | setlocal nomodifiable
```

### Setup options

When calling the `setup` function, the following options are available:

| option | default value | description |
| -----------------| --------------- | --------------------------------------------------------- |
| name | "BaleiaColors" | prefix used to name highlight groups |
| strip_ansi_codes | true | remove ANSI color codes from text |
| line_starts_at | 1 (one-indexed) | at which column start colorizing |
| colors | [NR_8][nr_8] | table mapping 256 color codes to vim colors |
| async | true | highlight asynchronously |
| log | "ERROR" | log level, possible values are ERROR, WARN, INFO or DEBUG |

## With Conjure

This can be used to colorize [Conjure][conjure] log buffer. To do it you must
tell conjure to not strip ANSI escape codes:

```vim
" tell Conjure to not strip ANSI sequences
let g:conjure#log#strip_ansi_escape_sequences_line_limit = 0
```

To automatically enable `baleia` for all Conjure log buffers use

```vim
let s:baleia = luaeval("require('baleia').setup { line_starts_at = 3 }")
autocmd BufWinEnter conjure-log-* call s:baleia.automatically(bufnr('%'))
```

## What to do if something looks wrong

Enable logs with

```vim
let s:baleia = luaeval("require('baleia').setup { log = 'DEBUG' }")
command! BaleiaLogs call s:baleia.logger.show()
```

You can set the log level to `ERROR`, `WARN`, `INFO` or `DEBUG`. You can see
the log using `BaleiaLogs`.

## Developer API

`baleia` provides two functions, `buf_set_lines` and `buf_set_text`, that have
the same interface as the default `vim.api.nvim_buf_set_lines` and
`vim.api.nvim_but_set_text`. Using those is very efficient because they do all
color detection and ANSI code stripping before writing anything to the buffer.
Example:

```lua
local new_lines = { '\x1b[32mHello \x1b[33mworld!' }

-- appending using Neovim standard API
local lastline = vim.api.nvim_buf_line_count(0)
vim.api.nvim_buf_set_lines(0, lastline, lastline, true, new_lines)

-- appending using Baleia API
local lastline = vim.api.nvim_buf_line_count(0)
local baleia = require('baleia').setup { }
baleia.buf_set_lines(0, lastline, lastline, true, new_lines)
```

[integration-badge]: https://github.com/m00qek/baleia.nvim/actions/workflows/integration.yml/badge.svg
[integration-runs]: https://github.com/m00qek/baleia.nvim/actions/workflows/integration.yml
[vim-plug]: https://github.com/junegunn/vim-plug
[conjure]: https://github.com/Olical/conjure
[packer]: https://github.com/wbthomason/packer.nvim
[nr_8]: ./lua/baleia/styles/themes.lua