Micron Document
ansi colors everywhere (or at least Neovim)

motivation

I've been playing with ANSI colors a lot because I'm going to resume using color in my notes. Visually they enable encoding additional semantic information into a block of text and it helps to decrease extraneous cognitive load. Not something I read, just something I feel. So I'm going to try it out for a while and see how I feel about it by way of ANSI escape sequences.

minimizing the burden on clients

I hope this eases the burden for clients, and it seems like the most responsible way to do this:

• only use ansi colors in pre-formatted text
• keep escape sequences short
• always terminate them
• never span multiple lines

only pre-formatted text

My use of them in pre-formatted blocks is also because Gemini doesn't support tables. So, as a hack, I'm going to play with some different table styles (simple & gitlab flavored markdown pipe tables) and see how things go.

Update: well, this makes sense in the case of studying because I use tables in preformatted blocks, but makes less sense when I'm trying to use the same color for something in a paragraph as in a figure. So I've already violated this rule.

short sequences

I will keep sequences limited to only a few words, with appropriate resets when they are done.

never span multiple lines

I also will NOT span multiple lines with the same escape. That just feels irresponsible, but it's based on the assumption that preformatted text wont be wrapped by clients.

well, maybe sometimes not short

I'm considering violating keep escape sequences short for screenshots, but maybe I'll just use images for those.

other thoughts

Clients can freely strip them, so I don't think it's going to matter much. Though some clients render them strangely when they apply their own color schemes to content. Generally because those clients aren't checking to see if the code they are rendering contains an escape. I don't have a fix for these, but from what I've seen so far, the effects are somewhat mild. If anyone writes clients and would like to raise any issues, I'd love to hear about issues with escape sequences.

minimizing the burden on me

To make it easier to embed ANSI in notes, I've created a fairly dumb Neovim plugin called T383838ansihelper.nvim -- it somewhat relies on T383838ansi.nvim for rendering, but I provide a convenient toggle and a menu for insertion. The addon can be cloned from the ansihelper git repo.

I use T383838<Leader>ai for insert, T383838<Leader>aa for append, and T383838<Leader>at for toggling visibility. The first two (insert and append) will work to pop up a picker. And the third for toggling will only work if T383838ansi.nvim is also installed.

The specific behavior of the menu depends on what other niceties are installed. I think T383838stevearc/dressing.nvim is why it looks/works nicely in my setup. It's less nice for a vanilly neovim, but still perfectly functional.

This is what it looks like now to use T383838<Leader>ai (I have pending changes to add RGB foreground and background):

T282828
╭─────────────────────── Insert ANSI code before cursor ───────────────────────╮
│> 15 / 15│
├──────────────────────────────────────────────────────────────────────────────┤
│> Reset (0) │
│ Bold (1) │
│ Faint (2) │
│ Red (31) │
│ Green (32) │
│ Yellow (33) │
│ Blue (34) │
│ Magenta (35) │
│ Cyan (36) │
│ White (37) │
│ Bold Red (91) │
╰──────────────────────────────────────────────────────────────────────────────╯

With T383838dressing.nvim it's essentially an FZF dialog to pick a choice. If I pick Green, for example, the following escape sequence is inserted directly in front of the cursor: T383838\x1b[32m (Here I'm using T383838\x1b as a stand-in for the escape. Another common way is with octal: T383838\033)

So if I had T383838foo bar baz and wanted the T383838bar to be green, I'd use T383838<Leader>ai on the T383838b of T383838bar and pick Green (32). Then I would use T383838<Leader>aa on the T383838r of T383838bar and hit enter to automatically pick Reset (0).

The final result would be something like this:

foo bar baz

what does this look like?

For example, I had a note with a sentence and the vocabulary word 传说:

T282828
| Context |
|-----------------------------------------------------|
| 你是否听说过这个村庄的传说? |
| Nǐ shìfǒu tīngshuōguò zhège cūnzhuāng de chuánshuō? |
| Have you heard the legend of this village? |

This makes for a fairly mild example, but it shows using the same color to highlight the same thing. This makes it easy to quickly find the term and see what's around it.

It also looks nice in T383838bat.

Tags: index

Tags
Navigation
Backlinks


created: 2026-03-01

(re)generated: 2026-07-17