Skip to content

Setting ENV["NO_COLOR"] = "1" inside Ruby does not disable colors #3

@davetron5000

Description

@davetron5000

It seems lipgloss reads the UNIX environment sometime early in its lifecycle such that changes to it later don't have any effect:

# test.rb
require "lipgloss"

if ARGV[0] == "no"
  puts "Disabling colors"
  ENV["NO_COLOR"] = "1"
end
puts Lipgloss::Style.new.foreground("#ffff00").render("HELLO")
> ruby test.rb
HELLO (in yellow)
> NO_COLOR=1 ruby test.rb
HELLO (not colored)
> ruby test.rb no
Disabling colors
HELLO (in yellow)
Image

Ultimatley, I'm trying to disable colors during a test. By the time my code runs, even in a test, whatever Lipgloss does to decide if colors should be used has been decided as "yes". In the go version's faq, it implies you can call lipgloss.SetColorProfile(termenv.TrueColor) (or some other value from termenv) to force its behavior. Is this possible with the Ruby version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions