Allow customization of base 16 ANSI terminal colors
Closed this issue · 2 comments
Hi Garrick, great work on rsthemes. It prompted me to upgrade to RStudio v1.4 and I am a big fan of the new customizability.
I gave Night Owl a try and noticed it does not change the terminal colors. For example, here's the terminal output when I load the tidyverse:
I expected the reds, greens, and blues in the terminal to match the the Night Owl terminal colors in https://github.com/sdras/night-owl-vscode-theme/blob/main/themes/Night%20Owl-Light-color-theme.json (lines 168 to 183). Instead, the terminal is using .xtermColor1
(red) .xtermColor2
(green) and .xtermColor5
(blue) as defined in https://github.com/gadenbuie/rsthemes/blob/main/inst/templates/rstudio/_terminal.scss.
It would be great to customize these terminal colors to match the theme. Although the terminal supports 256 colors (far too many to customize), the base 16 colors are the most widely used. Colors 0 through 7 are Normal ANSI (black, red, green, yellow, blue, magenta, cyan, white) and colors 8 through 15 are Bright ANSI. I found https://jeffkreeftmeijer.com/vim-16-color/ to be a helpful reference on this.
If you wanted to allow for this functionality, here's how I think that could happen:
-
Edit
rstheme_command_palette()
in create.R to include the following parameters:ansi_black
,ansi_red
,ansi_green
,ansi_yellow
,ansi_blue
,ansi_magenta
,ansi_cyan
,ansi_white
,ansi_bright_black
,ansi_bright_red
,ansi_bright_green
,ansi_bright_yellow
,ansi_bright_blue
,ansi_bright_magenta
,ansi_bright_cyan
, andansi_bright_white
. That's a lot of new parameters though — an alternative would be to addansi_normal
andansi_bright
, each of which accepts a list with the named colors. -
Edit
.xtermColor0
to.xtermColor15
in _terminal.scss to accept the colors fromrstheme_command_palette()
.
Once complete, there would be some additional legwork to edit the templates in inst/templates
to modify the terminal colors per rstheme (Fairy Floss already does this, I'm now discovering). And of course the documentation in rstheme_command_palette
would need to be updated too.
I'm happy to give this a go myself and open a pull request if you'd like.
I'd love to support this and haven't yet mostly because I didn't have time to do the research mapping the .xtermColor0
classes to the normal human color names. (So thank you for that link!)
The way forward here would be:
-
Add SCSS variables in _terminal.scss for the basic colors for 0-15. You can use _defaults.css as a reference for this setup.
-
Create a new function similar to
rstheme_rainbow_parentheses()
calledrstheme_terminal_colors()
that takes arguments forblack
black_bright
red
red_bright
- etc...
and turns it into a list with names equal to the SCSS variables from step 1. The class of that list would be classed
c("_terminal", "rstheme_template", "list")
.
That's pretty much it! @nsgrantham if you want to take a shot at this I'd happily work with you on a PR.