#216·color

failed to display color when piped to custom pager

Author: KarmenzindCreated Dec 6, 2023Updated Sep 9, 2024

Hi, I need to invoke pager in my app to display long text. Here is the sample code:

package main

import (
	"fmt"
	"os"
	"os/exec"
	"strings"

	"github.com/fatih/color"
)

func main() {
    var Yellow = color.New(color.FgYellow).SprintfFunc()
    fmt.Println(Yellow("from fmt.Println"))

    var pager = exec.Command("less", "-F")
	pager.Stdin = strings.NewReader(Yellow("from pager"))
	pager.Stdout = os.Stdout

	err := pager.Run()
	if err != nil {
            fmt.Println(err)
	}
}

It worked on Archlinux: image

but failed on Debian (bookworm, on rasberrypi) and latest MacOS: image

I don't think this was caused by your package but I wonder if you have any idea how to fix it. Thanks very much.