Piping to pager (eg. less -R) loses all color #122
-
I must be missing something obvious, but when I pipe any output of lipgloss to a pager, I lose all color formatting. I'm aware I need to use a -R flag on less in order to preserve escape codes. However, I can pipe straight to vim and see that no codes are preserved. A minimal example: package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
func main() {
style := lipgloss.NewStyle().Foreground(lipgloss.Color("4"))
fmt.Println(style.Render("Hello, world"))
} $ go run ./ Output to terminal(In blue) Hello, world $ go run ./ | less -R Output to less -R(No color) Hello, world Expected output to less -R(In blue) Hello, world Am I missing something?? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
lipgloss.SetColorProfile(termenv.TrueColor) CLICOLOR_FORCE=1 go run . |
Beta Was this translation helpful? Give feedback.
lipgloss
(or rathertermenv
in the background) detects that the output isn't connected to a terminal and strips the styling. You can either set a color profile manually or set an environment variable which enforces colored output:CLICOLOR_FORCE=1 go run .