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

Escaped escape codes when overriding ValueStyle and value needs quoting #19

Closed
tombell opened this issue Feb 23, 2023 · 0 comments · Fixed by #20 or #30
Closed

Escaped escape codes when overriding ValueStyle and value needs quoting #19

tombell opened this issue Feb 23, 2023 · 0 comments · Fixed by #20 or #30
Labels
bug Something isn't working

Comments

@tombell
Copy link
Contributor

tombell commented Feb 23, 2023

I was trying to override log.ValueStyle to add some colour, however due to it being quoted after the ValueStyle.Render(val) the added escape codes themselves end up escaped.

package main

import (
    "os"

    "github.com/charmbracelet/lipgloss"
    "github.com/charmbracelet/log"
)

func main() {
    logger := log.New(
        log.WithOutput(os.Stderr),
         log.WithTimestamp()
    )
    log.ValueStyle = lipgloss.NewStyle().
        Foreground(lipgloss.AdaptiveColor{Light: "208", Dark: "192"})
    logger.Info("testing overriding global styles", "key", "val", "foo", true)
}

This results in the following output in the terminal

charmbracelet/log output

The expected output would be

expected charmbracelet/log output

I would guess that the fix would be to call lipgloss.Render(val) after the value has been escaped to prevent the lipgloss escape codes from being escaped as part of the value.

@aymanbagabas aymanbagabas added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Feb 23, 2023
@tombell tombell closed this as completed Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants