Skip to content

Add Lipgloss.color_profile= to force colors on or off - #13

Merged
marcoroth merged 1 commit into
mainfrom
color-profile
Nov 19, 2026
Merged

marcoroth merged 1 commit into
mainfrom
color-profile

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request adds Lipgloss.color_profile, Lipgloss.color_profile=, and Lipgloss.has_dark_background=, which call Lip Gloss' ColorProfile, SetColorProfile, and SetHasDarkBackground.

Lip Gloss detects the color profile from the terminal and the environment the first time it renders, and there was no way to change it from Ruby. Setting ENV["NO_COLOR"] after that point had no effect, and output that isn't a terminal, such as CI or tests, never had colors, even with FORCE_COLOR or COLORTERM set.

Lipgloss.color_profile                # => :true_color, :ansi256, :ansi, or :ascii

Lipgloss.color_profile = :ascii       # never render colors
Lipgloss.color_profile = :true_color  # always render colors, even when not a terminal
Lipgloss.has_dark_background = true   # pick the dark variant of adaptive colors

With output piped, so not a terminal:

style = Lipgloss::Style.new.foreground("212").bold(true)

style.render("hello")                # => "hello"
Lipgloss.color_profile = :ansi256
style.render("hello")                # => "\e[1;38;5;212mhello\e[0m"

In a terminal with colors, Lipgloss.color_profile = :ascii renders "hello" without colors from then on.

An unknown profile raises an ArgumentError. The README documents the new methods under Colors and Module Methods.

Resolves #3
Resolves #10

@marcoroth
marcoroth merged commit d40c91c into main Nov 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant