Piping to pager (eg. less -R) loses all color #122
Answered
by
muesli
rockorager
asked this question in
Q&A
-
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.
Answered by
muesli
Sep 22, 2022
Replies: 1 comment 1 reply
-
lipgloss.SetColorProfile(termenv.TrueColor) CLICOLOR_FORCE=1 go run . |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rockorager
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 .