diff --git a/menu.go b/menu.go index 01084d2..e198b9d 100644 --- a/menu.go +++ b/menu.go @@ -15,6 +15,7 @@ import ( "strconv" "strings" + "github.com/mattn/go-isatty" wlog "gopkg.in/dixonwille/wlog.v2" ) @@ -23,6 +24,11 @@ const ( n ) +var ( + NoColor = os.Getenv("TERM") == "dumb" || + (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) +) + //Menu is used to display options to a user. //A user can then select options and Menu will validate the response and perform the correct action. type Menu struct { @@ -69,7 +75,9 @@ func NewMenu(question string) *Menu { //errorColor changes the color of the question. //Use wlog.None if you do not want to change the color. func (m *Menu) AddColor(optionColor, questionColor, responseColor, errorColor wlog.Color) { - m.ui = wlog.AddColor(questionColor, errorColor, wlog.None, wlog.None, optionColor, responseColor, wlog.None, wlog.None, wlog.None, m.ui) + if !NoColor { + m.ui = wlog.AddColor(questionColor, errorColor, wlog.None, wlog.None, optionColor, responseColor, wlog.None, wlog.None, wlog.None, m.ui) + } } //ClearOnMenuRun will clear the screen when a menu is ran.