Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty line added when filtering to 'less -R' #157

Closed
lyderic opened this issue Feb 6, 2022 · 2 comments · Fixed by #192
Closed

Empty line added when filtering to 'less -R' #157

lyderic opened this issue Feb 6, 2022 · 2 comments · Fixed by #192

Comments

@lyderic
Copy link

lyderic commented Feb 6, 2022

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.

fatih added a commit that referenced this issue Mar 12, 2023
The newline should be added after wrapping the input with escape
sequences. That way `less` or other commands can parse the output
correctly.

fixes #157
@fatih
Copy link
Owner

fatih commented Mar 12, 2023

Hi @lyderic

Thanks for the feedback. I know it's late, but I've opened a fix: #192 you can check it out yourselves as well.

fatih added a commit that referenced this issue Mar 12, 2023
The newline should be added after wrapping the input with escape
sequences. That way `less` or other commands can parse the output
correctly.

fixes #157
@lyderic
Copy link
Author

lyderic commented Aug 16, 2023

Many thanks for sorting this out!
L

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants