Module terminal

Highlights terminal CSI ANSI color codes.

Functions

initialize_terminal_colors () Return a lookup table from [0,255] to an RGB color.
highlight_buffer (buf[, ns=DEFAULT_NAMESPACE], lines, line_start[, rgb_color_table=initialize_terminal_colors()]) Highlight the buffer region.
attach_to_buffer (buf[, rgb_color_table=initialize_terminal_colors()]) Attach to a buffer and continuously highlight changes.
setup (rgb_color_table) Easy to use function if you want the full setup without fine grained control.

Fields

DEFAULT_NAMESPACE Default namespace used in highlight_buffer and attach_to_buffer.


Functions

initialize_terminal_colors ()
Return a lookup table from [0,255] to an RGB color. Respects g:terminalcolorn

Returns:

    {[number]=string} number to hex string
highlight_buffer (buf[, ns=DEFAULT_NAMESPACE], lines, line_start[, rgb_color_table=initialize_terminal_colors()])
Highlight the buffer region. Highlight starting from line_start (0-indexed) for each line described by lines in the buffer buf and attach it to the namespace ns.

Parameters:

  • buf integer buffer id.
  • ns integer the namespace id. Create it with vim.api.create_namespace (default DEFAULT_NAMESPACE)
  • lines {string,...} the lines to highlight from the buffer.
  • line_start integer should be 0-indexed
  • rgb_color_table {[number]=string} cterm color RGB lookup table (default initialize_terminal_colors())

Usage:

  • -- Re-highlights the current buffer
    local terminal = require 'terminal'
    -- Clear existing highlight
    vim.api.nvim_buf_clear_namespace(buf, terminal.DEFAULT_NAMESPACE, 0, -1)
    local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
    terminal.highlight_buffer(0, nil, lines, 0)
  • local function rehighlight_region(buf, line_start, line_end)
      local ns = terminal.DEFAULT_NAMESPACE
      vim.api.nvim_buf_clear_namespace(buf, ns, line_start, line_end)
      local lines = vim.api.nvim_buf_get_lines(0, line_start, line_end, false)
      terminal.highlight_buffer(0, nil, lines, line_start)
    end
attach_to_buffer (buf[, rgb_color_table=initialize_terminal_colors()])
Attach to a buffer and continuously highlight changes.

Parameters:

  • buf integer A value of 0 implies the current buffer.
  • rgb_color_table {[number]=string} cterm color RGB lookup table (default initialize_terminal_colors())

See also:

setup (rgb_color_table)
Easy to use function if you want the full setup without fine grained control. Establishes an autocmd for FileType terminal

Parameters:

  • rgb_color_table

Usage:

    require'terminal'.setup()

Fields

DEFAULT_NAMESPACE
Default namespace used in highlight_buffer and attach_to_buffer. The name is "terminal_highlight"

See also:

generated by LDoc 1.4.6 Last updated 2019-10-16 07:43:49