As a user of iTerm2 and a developer that wants to use python packages supporting colorization such as Rich, I want to extract the colors from my iTerm2 Profile into an RGB dataset that provides:
- Background (R,G,B)
- Foreground (R,G,B)
- List of 8 "normal" colors of (R, G, B)
- List of 8 "bright" colors of (R, G, B)
You will first need to export your profile colors from iTerm, as described in the section below. You can then either use this package directly or programaticaly.
direct module
Consider an iTerm profile with color values that look like this in the app:
After exporting these settings to the default filename "Untitled.itemcolors", run python:
python -m iterm2_colors2rgb Untitled.itermcolors
Outputs (formatted for clarity):
(
(0, 0, 0),
(199, 199, 199),
[(0, 0, 0), (201, 27, 0), (0, 194, 0), (199, 196, 0), (2, 37, 199), (202, 48, 199), (0, 197, 199), (199, 199, 199), (104, 104, 104)],
[(255, 110, 103), (95, 250, 104), (255, 252, 103), (104, 113, 255), (255, 119, 255), (96, 253, 255), (255, 255, 255)]
)
programmatic
from iterm2_colors2rgb import iterm2_colors2rgb
# as a tuple (bg, fb, normal_list, bright_list)
colors = iterm2_colors2rgb("Untitled.itermcolors")
pip install iterm2-colors2rgb
Steps:
- Open the iTerm2 app settings
- Select the Prefrences option
- Select the Profiles option
- Select the profile that you want to export
- Click the Color Presents ... dropdown to reveal the Export option
- Click the Export option
You will then be presented with a Save File diaglog box which allows you to choose the name and location where you want to save your settings.
If you are using the Rich package and you want to save your console output to file with thes colors you can
from rich.console import TerminalTheme, Console
HTML_SAVE_THEME = TerminalTheme(
(0, 0, 0),
(199, 199, 199),
[(0, 0, 0),
(201, 27, 0),
(0, 194, 0),
(199, 196, 0),
(2, 37, 199),
(202, 48, 199),
(0, 197, 199),
(199, 199, 199),
(104, 104, 104)],
[(255, 110, 103),
(95, 250, 104),
(255, 252, 103),
(104, 113, 255),
(255, 119, 255),
(96, 253, 255),
(255, 255, 255)]
)
# create the Console instance with `record=True` to use the save methods
console = Console(record=True)
# ... console.print(...) usage to render text to screen
# now save the console output to an HTML file using the color theme
console.save_html('mytabledata.html', theme=HTML_SAVE_THEME)