Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithProfile not respected in custom rendered #267

Open
goyapara-deshaw opened this issue Mar 12, 2024 · 1 comment
Open

WithProfile not respected in custom rendered #267

goyapara-deshaw opened this issue Mar 12, 2024 · 1 comment
Milestone

Comments

@goyapara-deshaw
Copy link

goyapara-deshaw commented Mar 12, 2024

Describe the bug
When a custom renderer is defined with the WithProfile method, it is not being respected, when TERM=xterm and COLORTERM is unset.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS Linux
  • Shell bash
  • Terminal Emulator PuTTy

To Reproduce
export TERM=xterm
unset COLORTERM

and run the below code:

package main

import (
        "fmt"
        "os"

        "github.com/charmbracelet/lipgloss"
        "github.com/muesli/termenv"
)

func main() {
        renderer := lipgloss.NewRenderer(os.Stdout, termenv.WithProfile(termenv.TrueColor))
        style := renderer.NewStyle().Foreground(lipgloss.Color("#FF0000")) // bright red
        fmt.Fprint(os.Stdout, style.Render("Hello, World!"))
}

Source Code
We have to explicitly do:

package main

import (
        "fmt"
        "os"

        "github.com/charmbracelet/lipgloss"
        "github.com/muesli/termenv"
)

func main() {
        renderer := lipgloss.NewRenderer(os.Stdout, termenv.WithProfile(termenv.TrueColor))
		renderer.SetColorProfile = termenv.TrueColor
        style := renderer.NewStyle().Foreground(lipgloss.Color("#FF0000")) // bright red
        fmt.Fprint(os.Stdout, style.Render("Hello, World!"))
}

Expected behavior
It should render in color.

@bashbunni bashbunni added this to the v2.0.0 milestone Sep 16, 2024
@bashbunni
Copy link
Member

In v2 this is what it would look like to set the color profile outside of a Bubble Tea app:

func main() {
        // detect the environment's capabilities
	w := colorprofile.NewWriter(os.Stdout, os.Environ())
	// Pretend we want to force truecolor.
        w.Profile = colorprofile.TrueColor
	style := lipgloss.NewStyle().Foreground(lipgloss.Color("#FF0000")) // bright red
	fmt.Fprint(w, style.Render("Hello, World!"))
}

using colorprofile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants