#programming-language #github #xterm #color #query #query-language #linguist

bin+lib linguist-termcolor

Query GitHub's library for colors for programming languages

3 releases

0.1.2 May 27, 2024
0.1.1 May 25, 2024
0.1.0 May 25, 2024

#765 in Development tools

MIT/Apache

20KB
219 lines

linguist-termcolor

Query GitHub's Linguist library for colors for programming languages.

cargo install linguist-termcolor
$ linguist-termcolor for rust
rgb #dea584 xterm 180 rust

I needed xterm colors for Spaceship 😎 but then it got out of hand.


lib.rs:

Query GitHub's Linguist library for colors for programming languages.

$ linguist-termcolor for rust
 rgb #dea584 xterm 180 rust

You can query with language names or file extensions.

xterm colors and color distances

For finding the nearest xterm colors, a --colors/-c option is available for specifying the color model or color space in which to calculate color differences using color_art::distance_with.

The default is RGB, which may not actually yield the best result in terms of human perception. For finding colors that "look" the closest, CIELAB is a reasonable choice; use it with -c lab. See ColorSpace for available choices.

For example, here are the different results for "python" using RGB, CMYK, and CIELAB, respectively.

$ linguist-termcolor -c rgb for python
 rgb #3572a5 xterm 61 python
$ linguist-termcolor -c cmyk for python
 rgb #3572a5 xterm 67 python
$ linguist-termcolor -c lab for python
 rgb #3572a5 xterm 24 python

Dependencies

~9–21MB
~303K SLoC