color icon indicating copy to clipboard operation
color copied to clipboard

Empty line added when filtering to 'less -R'

Open lyderic opened this issue 3 years ago • 0 comments

This is a minimal program to reproduce the issue (I am on Ubuntu Linux 20.04 and I use gnome-terminal):

package main

import "github.com/fatih/color"

func main() {
    red := color.New(color.FgRed)
    color.NoColor = false
    red.Println("foo")
}

When run, the above program displays foo in red. Good.

However, when the output is piped to less -FR, an empty line is added:

$ go run main.go
foo
$ go run main.go | less -FR
foo
            <--- empty line here :-(
$ go run main.go | less -F
ESC[31mfoo
ESC[0m

Please note that in the output above, foo on lines 2 and 4 is rendered in red on my screen. One can see that the raw line ESC[0m is added at the end, which is not the desired output, I think.

The desired output would be:

$ go run main.go | less -F
ESC[31mfooESC[0m

Thanks for looking at it.

lyderic avatar Feb 06 '22 05:02 lyderic