File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,10 @@ import (
99 "github.com/mgutz/ansi"
1010)
1111
12+ var _isColorEnabled = true
1213var _isStdoutTerminal = false
1314var checkedTerminal = false
15+ var checkedNoColor = false
1416
1517func isStdoutTerminal () bool {
1618 if ! checkedTerminal {
@@ -33,13 +35,21 @@ func NewColorable(f *os.File) io.Writer {
3335func makeColorFunc (color string ) func (string ) string {
3436 cf := ansi .ColorFunc (color )
3537 return func (arg string ) string {
36- if isStdoutTerminal () {
38+ if isColorEnabled () && isStdoutTerminal () {
3739 return cf (arg )
3840 }
3941 return arg
4042 }
4143}
4244
45+ func isColorEnabled () bool {
46+ if ! checkedNoColor {
47+ _isColorEnabled = os .Getenv ("NO_COLOR" ) == ""
48+ checkedNoColor = true
49+ }
50+ return _isColorEnabled
51+ }
52+
4353// Magenta outputs ANSI color if stdout is a tty
4454var Magenta = makeColorFunc ("magenta" )
4555
Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ func OpenInBrowser(url string) error {
2222}
2323
2424func RenderMarkdown (text string ) (string , error ) {
25- return glamour .Render (text , "dark" )
25+ style := "notty"
26+ if isColorEnabled () {
27+ style = "dark"
28+ }
29+ return glamour .Render (text , style )
2630}
2731
2832func Pluralize (num int , thing string ) string {
You can’t perform that action at this time.
0 commit comments