Skip to content

Displaying ANSI escape code colours in the log buffer

Dave Yarwood edited this page Jan 5, 2022 · 2 revisions

This is a follow up to #53 and the features that were added to support the concept.

Background

If your program outputs ANSI escape codes to be coloured by your terminal you may have noticed that Conjure is stripping them out automatically as they enter the log buffer. If you would like to have these codes appended to the log as is you can set log.strip-ansi-escape-sequences-line-limit to 0.

Now you can install an ANSI escape code highlighting plugin and configure it for your Conjure log buffer. There are various options for this, some of which are described below.

Baleia

The plugin baleia.nvim works well, and includes Conjure-specific instructions in the README.

AnsiEsc

Ollie created a fork of the AnsiEsc plugin to improve the behaviour for this context, you can download that from Olical/AnsiEsc.

The original AnsiEsc replaces the current language highlighting with plain text + ANSI escape code highlighting, my fork overlays the ANSI codes on top of the current language in the log. This process isn’t perfect but it’s a step in the right direction.

Now run :AnsiEsc in the log buffer and you should have some level of support for your original language + ANSI escape code colouring! You may also be interested in using this autocmd that @daveyarwood (comment).

" Automatically enable AnsiEsc (interpret ANSI escape codes) for the Conjure log buffer.
autocmd BufEnter conjure-log-* AnsiEsc