Skip to content

Commit

Permalink
Fix linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanello1908 committed Jul 28, 2024
1 parent bac65c2 commit 8dc517b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions client/color/color_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package color

import (
"os"

auroraLib "github.com/logrusorgru/aurora"
"github.com/mattn/go-isatty"
)

// We're using a couple of libraries that produce ANSI escape sequences to print
// colored text:
//
// * aurora
// * zerolog
//
// Ideally, both of these libraries would support the standard NO_COLOR
// environment variable, but they don't, so we need to handle it ourselves.
// Fortunately, both libraries include an option to disable colors, so we can
// check for NO_COLOR ourselves and disable color manually if needed.
//
// Another consideration is that not all terminal environments support ANSI
// escape codes (the Windows 7 CMD terminal doesn't, for example). So, we try to
// detect that scenario and disable colors. It would be good to do this in a
// more robust way, something like checking the terminfo/termcap capabilities of
// the terminal to see if it's capable of interpreting ANSI escape sequences,
// but that seems complex and error prone and I'm not really sure that it's
// worth it. So I'm taking a more basic approach here, where we just check to
// see if the terminal is a TTY and assume that if it is a TTY, then it can
// probably interpret ANSI escape sequences.
//
// Reference:
// https://github.com/logrusorgru/aurora/issues/2
// https://eklitzke.org/ansi-color-codes
var EnableColor = isatty.IsTerminal(os.Stdout.Fd()) &&
len(os.Getenv("NO_COLOR")) == 0

var Aurora auroraLib.Aurora

func init() {
// HACK: Ideally, aurora would support NO_COLOR, but at least they give us a
// config option so that we can disable color manually.
Aurora = auroraLib.NewAurora(EnableColor)
}
File renamed without changes.

0 comments on commit 8dc517b

Please sign in to comment.