Skip to content

Commit

Permalink
add check for supporting colors in terminal before add colors
Browse files Browse the repository at this point in the history
  • Loading branch information
RonQedit authored and Will Dixon committed Jan 5, 2018
1 parent 04748e3 commit 8ae9989
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strconv"
"strings"

"github.com/mattn/go-isatty"
wlog "gopkg.in/dixonwille/wlog.v2"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8ae9989

Please sign in to comment.