Skip to main content

Convert iTerm2 profile colors XML file to RGB

Project description

Convert iTerm2 profile colors to RGB dataset

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)

Usage

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:

colors in iTerm

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")

Installation

pip install iterm2-colors2rgb

Exporting Profile Colors from iTerm

export steps

Steps:

  1. Open the iTerm2 app settings
  2. Select the Prefrences option
  3. Select the Profiles option
  4. Select the profile that you want to export
  5. Click the Color Presents ... dropdown to reveal the Export option
  6. 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.

Usage with Rich TerminalTheme

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iterm2-colors2rgb-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iterm2_colors2rgb-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file iterm2-colors2rgb-0.1.0.tar.gz.

File metadata

  • Download URL: iterm2-colors2rgb-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for iterm2-colors2rgb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b5f3c7c1d0bd5374ec1e5aaaba76d1708edface93b84ee8b75742f8d251efae
MD5 94cc303157fa30932d786d7b9904683e
BLAKE2b-256 166b43b1129be0865d2f6618b4196dc56206f11b9e3d9bd5b71a6c45397190cc

See more details on using hashes here.

File details

Details for the file iterm2_colors2rgb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iterm2_colors2rgb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for iterm2_colors2rgb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8599e7b7ea72c03011cf2d74c4035a34637b7314d8bdc120bda38622c9589d4c
MD5 930cfda15ad218eb42abc2afad1df3ea
BLAKE2b-256 cc67e94fb7b27b6f4420c4ee454bf412cc8754862922581249725e761864580f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page