// Scolorf returns a string colorized for terminal output using the syntaxCode (unless that's empty).
// Requires the syntax defined on https://github.com/wsxiaoys/terminal/blob/master/color/color.go .
437934
func Scolorf(syntaxCode string, format string, args ...interface{}) string {
	plainFormatted := fmt.Sprintf(format, args...)
	if len(syntaxCode) > 0 && TerminalColorsEnabled {
		// cannot pass the code as a string param
		return color.Sprintf(syntaxCode+"\n %s", plainFormatted)
	}
	return plainFormatted
}
899261
func OptionPrefixTextColor(x Color) Option {
	return func(p *Prompt) error {
		p.renderer.prefixTextColor = x
		return nil
	}
}
35825
func OptionInputBGColor(x Color) Option {
	return func(p *Prompt) error {
		p.renderer.inputBGColor = x
		return nil
	}
}
1283110
func Yellow(arg interface{}) Value {
	if val, ok := arg.(Value); ok {
		return val.Yellow()
	}
	return value{value: arg, color: YellowFg}
}
286178
func IsColor(s string) bool {
	r := []rune(s)
	if len(r) != 2 {
		return false
	}
	a := r[1] >= 48 && r[1] <= 57
	b := r[1] >= 97 && r[1] <= 102
	return a || b
}
976533
func (t *Terminfo) TColor(fi, bi int) string {
	rv := ""
	// As a special case, we map bright colors to lower versions if the
	// color table only holds 8.  For the remaining 240 colors, the user
	// is out of luck.  Someday we could create a mapping table, but its
	// not worth it.
	if t.Colors == 8 {
		if fi > 7 && fi < 16 {
			fi -= 8
		}
		if bi > 7 && bi < 16 {
			bi -= 8
		}
	}
	if t.Colors > fi && fi >= 0 {
		rv += t.TParm(t.SetFg, fi)
	}
	if t.Colors > bi && bi >= 0 {
		rv += t.TParm(t.SetBg, bi)
	}
	return rv
}
194839
func Italic(arg interface{}) Value {
	if val, ok := arg.(Value); ok {
		return val.Italic()
	}
	return value{value: arg, color: ItalicFm}
}
354811
func (a *Writer) BColor256(color int) (int, error) {
	return a.WriteString(BColor256(color))
}
737382
func (u *UI) ColorString(c Color, s string) string {
	if !u.EnableColors {
		return s
	}

	ctx := ansiterm.Context{
		Foreground: ansiterm.Color(c),
	}

	return createStyledString(ctx, s)
}
1157390
func (c Color) String() string {
	fa := float64(c.A) / float64(255)
	return fmt.Sprintf("rgba(%v,%v,%v,%.1f)", c.R, c.G, c.B, fa)
}
1212007
func (writer *baseFileWriter) Colored() bool {
	writer.lock.RLock()
	defer writer.lock.RUnlock()
	return writer.colored
}
729979
func (o *TextOutput) colorOn(num1 int, num2 int) string {
	if o.color {
		return fmt.Sprintf("\033[%d;%dm", num1, num2)
	}
	return ""
}
1320242
func Stderr() io.Writer {
	stderr := colorable.NewColorableStderr()
	if stderr == os.Stderr {
		return os.Stderr
	}

	return &WinColorTerminal{output: stderr}
}
1357907
func NewColoredConsole(opts string) logger.Provider {
	config := NewConsoleOpts()
	logger.UnmarshalOpts(opts, &config)
	p := &ColoredConsole{
		config: config,
		stdout: colorable.NewColorableStdout(),
		stderr: colorable.NewColorableStderr(),
	}
	if f, ok := p.stdout.(*os.File); ok {
		p.stdoutColorable = isatty.IsTerminal(f.Fd())
	}
	if f, ok := p.stderr.(*os.File); ok {
		p.stderrColorable = isatty.IsTerminal(f.Fd())
	}
	return p
}
503396
func (w *Wrapper) PrintColor(ctx *ansiterm.Context, value interface{}) {
	if ctx != nil {
		ctx.Fprintf(w.TabWriter, "%v\t", value)
	} else {
		fmt.Fprintf(w, "%v\t", value)
	}
}
727895
func parseLsColors(lsColors string) {
	for i := 0; i < len(lsColors); i += 2 {
		if i == 0 {
			colorMap["directory"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 2 {
			colorMap["symlink"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 4 {
			colorMap["socket"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 6 {
			colorMap["pipe"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 8 {
			colorMap["executable"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 10 {
			colorMap["block"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 12 {
			colorMap["character"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 14 {
			colorMap["executable_suid"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 16 {
			colorMap["executable_sgid"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 18 {
			colorMap["directory_o+w_sticky"] =
				getColorFromBsdCode(lsColors[i : i+2])
		} else if i == 20 {
			colorMap["directory_o+w"] =
				getColorFromBsdCode(lsColors[i : i+2])
		}
	}
}
1304904
func Colorize(color int, msg string) string {
	//FIXME(Sha): This logic assumes that because tty is set that the terminal supports colors.
	//	This needs to be fixed via bringing in PDCurses or some other library.
	if !stdoutIsTTY {
		return msg
	}

	// Uses basic color set rather than extended set.
	return fmt.Sprintf("\033[0;%dm%s%s", color, msg, ResetCode)
}