charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
3.32k stars 56 forks source link

freeze issue with lipgloss* colors #117

Open jkellogg01 opened 3 months ago

jkellogg01 commented 3 months ago

Describe the bug freeze appears to be changing the colors of captured terminal output and I'm not sure why.

Reproduction Here is a minimal reproduction of the issue I'm experiencing:

package main

import (
        "fmt"

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

func main() {
        l := list.New(
                elem("dotstash", "by sowing"),
                elem("other-config", "by joe standard"),
                elem("this one is empty", "by john testman"),
        ).Enumerator(func(items list.Items, index int) string { return "" }).
                ItemStyleFunc(func(items list.Items, index int) lipgloss.Style {
                        def := lipgloss.NewStyle().
                                Padding(0, 1).MarginBottom(1).Border(lipgloss.NormalBorder(), false, false, false, true)
                        if index == 0 {
                                highlight := lipgloss.Color("#F780E2")
                                return def.Foreground(highlight).BorderForeground(highlight)
                        }
                        return def
                })
        fmt.Println(l)
}

func elem(title, desc string) string {
        return lipgloss.JoinVertical(0,
                lipgloss.NewStyle().Bold(true).Render(title),
                lipgloss.NewStyle().Italic(true).Render(desc),
        )
}

When the program is run, the first element will be entirely pink, but when the output is captured by freeze using the -x flag, the left border will remain pink, while the text will have the color removed.

Expected behavior Commands that output color that is normally entirely colored are instead stripped of their color when the output is captured using freeze -x <command>

Screenshots

first screenshot is captured output from the program I'm working on, second is captured output from the reproduction program above.

output from my actual program

repro output

Desktop (please complete the following information):

jkellogg01 commented 3 months ago

this also might have something to do with the use of lipgloss.JoinVertical; when I removed it from my reproduction the colors were rendered correctly:

package main

import (
        "fmt"

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

func main() {
        l := list.New(
                "dotstash",
                "other-config",
        ).Enumerator(func(items list.Items, index int) string { return "" }).
                ItemStyleFunc(func(items list.Items, index int) lipgloss.Style {
                        def := lipgloss.NewStyle().
                                Padding(0, 1).MarginBottom(1).Border(lipgloss.NormalBorder(), false, false, false, true)
                        if index == 0 {
                                highlight := lipgloss.Color("#F780E2")
                                return def.Foreground(highlight).BorderForeground(highlight)
                        }
                        return def
                })
        fmt.Println(l)
}

test-smaller