glamour icon indicating copy to clipboard operation
glamour copied to clipboard

termenv.ANSI ColorProfile being reverted in indented text

Open bmeneg opened this issue 3 years ago • 2 comments

When using the termenv.ANSI color profile for a normal text it works just fine, but in indented text it gets back to the default ANSI256. The following is an output example using a pager (most) with support only for the 4bits (16) colors:

!177 CNB: bitfield: add FIELD_MAX() and field_max()
===================================

  Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1939478
  Tested: Just build

^[[38;5;251m    ^[[38;5;251mcommit e31a50162feb352147d3fc87b9e036703c8f2636
    ^[[38;5;251mAuthor: Alex Elder <[email protected]>
    ^[[38;5;251mDate:   Thu Mar 12 11:44:27 2020 -0500
    ^[[38;5;251m
    ^[[38;5;251m    bitfield.h: add FIELD_MAX() and field_max()
    ^[[38;5;251m
    ^[[38;5;251m    Define FIELD_MAX(), which supplies the maximum value that can be
    ^[[38;5;251m    represented by a field value.  Define field_max() as well, to go
    ^[[38;5;251m    along with the lower-case forms of the field mask functions.
    ^[[38;5;251m
    ^[[38;5;251m    Signed-off-by: Alex Elder <[email protected]>
    ^[[38;5;251m    Acked-by: Jakub Kicinski <[email protected]>
    ^[[38;5;251m    Signed-off-by: David S. Miller <[email protected]>

  Signed-off-by: Ivan Vecera [email protected] mailto:[email protected]

The original text is as follows:

!177 CNB: bitfield: add FIELD_MAX() and field_max()
===================================

  Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1939478
  Tested: Just build

    commit e31a50162feb352147d3fc87b9e036703c8f2636
    Author: Alex Elder <[email protected]>
    Date:   Thu Mar 12 11:44:27 2020 -0500

        bitfield.h: add FIELD_MAX() and field_max()

        Define FIELD_MAX(), which supplies the maximum value that can be
        represented by a field value.  Define field_max() as well, to go
        along with the lower-case forms of the field mask functions.

        Signed-off-by: Alex Elder <[email protected]>
        Acked-by: Jakub Kicinski <[email protected]>
        Signed-off-by: David S. Miller <[email protected]>

  Signed-off-by: Ivan Vecera [email protected] mailto:[email protected]

When using a pager that supports more colors, it's possible to see the color difference between the indented text.

bmeneg avatar Mar 17 '21 20:03 bmeneg

Hi there, I run most by default, and I can't get it to work when using glow, based on your issue, you are saying that there is no way around this issue as it is a limitation of most itself, am I correct?

jpmvferreira avatar Dec 28 '21 14:12 jpmvferreira

I worked it around by completely dropping the ANSI chars rendering when the output is sent to something different of a real terminal (e.g. pipe, cat file.txt | less):

func isOutputTerminal() bool {
       if !terminal.IsTerminal(syscall.Stdout) || !terminal.IsTerminal(syscall.Stderr) {
               return false
       }
       return true
}

But then you won't have any colors.

bmeneg avatar Dec 28 '21 15:12 bmeneg