Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Stringer interface for ansi color types #48

Merged
merged 1 commit into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions color.go
Expand Up @@ -26,12 +26,24 @@ type Color interface {

type NoColor struct{}

func (nc NoColor) String() string {
return ""
}

// ANSIColor is a color (0-15) as defined by the ANSI Standard.
type ANSIColor int

func (a ANSIColor) String() string {
return ansiHex[a]
}

// ANSI256Color is a color (16-255) as defined by the ANSI Standard.
type ANSI256Color int

func (a ANSI256Color) String() string {
return ansiHex[a]
}

// RGBColor is a hex-encoded color, e.g. "#abcdef".
type RGBColor string

Expand Down
4 changes: 3 additions & 1 deletion examples/hello-world/main.go
Expand Up @@ -37,5 +37,7 @@ func main() {
termenv.String("gray").Foreground(p.Color("0")).Background(p.Color("#B9BFCA")),
)

fmt.Printf("\n\t%s %t\n", termenv.String("Has dark background?").Bold(), termenv.HasDarkBackground())
fmt.Printf("\n\t%s %s\n", termenv.String("Has foreground color").Bold(), termenv.ForegroundColor())
fmt.Printf("\t%s %s\n", termenv.String("Has background color").Bold(), termenv.BackgroundColor())
fmt.Printf("\t%s %t\n", termenv.String("Has dark background?").Bold(), termenv.HasDarkBackground())
}