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

feat: color code app types #196

Merged
merged 4 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions internal/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,42 @@ func Italic(text string) string {
return color.Sprintf(color.Italic(text))
}

// Red returns text colored red
func Red(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.Red(text))
}

// Green returns text colored green
func Green(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.Green(text))
}

// Yellow returns text colored yellow
func Yellow(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.Yellow(text))
}

// Blue returns text colored blue
func Blue(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.Blue(text))
}

// Magenta returns text colored magenta
func Magenta(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.Magenta(text))
}

// Cyan returns text colored cyan
func Cyan(text string) string {
color := Color(os.Stdout)
return color.Sprintf(color.BrightCyan(text))
}

// Linkify returns an ANSI escape sequence with an hyperlink, if the writer
// supports colors.
func Linkify(text, url string, w io.Writer) string {
Expand Down
31 changes: 25 additions & 6 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func (v *applicationView) AsTableRow() []string {
if v.revealSecret {
return []string{
v.Name,
v.Type,
applyColor(v.Type),
ansi.Faint(v.ClientID),
ansi.Italic(v.ClientSecret),
strings.Join(v.Callbacks, ", "),
}
}
return []string{
v.Name,
v.Type,
applyColor(v.Type),
ansi.Faint(v.ClientID),
strings.Join(v.Callbacks, ", "),
}
Expand All @@ -94,7 +94,7 @@ func (v *applicationView) KeyValues() [][]string {
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"NAME", v.Name},
[]string{"DESCRIPTION", v.Description},
[]string{"TYPE", v.Type},
[]string{"TYPE", applyColor(v.Type)},
[]string{"CLIENT SECRET", ansi.Italic(v.ClientSecret)},
[]string{"CALLBACKS", callbacks},
[]string{"ALLOWED LOGOUT URLS", allowedLogoutURLs},
Expand All @@ -109,7 +109,7 @@ func (v *applicationView) KeyValues() [][]string {
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"NAME", v.Name},
[]string{"DESCRIPTION", v.Description},
[]string{"TYPE", v.Type},
[]string{"TYPE", applyColor(v.Type)},
[]string{"CALLBACKS", callbacks},
[]string{"ALLOWED LOGOUT URLS", allowedLogoutURLs},
[]string{"ALLOWED ORIGINS", allowedOrigins},
Expand Down Expand Up @@ -145,14 +145,14 @@ func (v *applicationListView) AsTableRow() []string {
return []string{
ansi.Faint(v.ClientID),
v.Name,
v.Type,
applyColor(v.Type),
ansi.Italic(v.ClientSecret),
}
}
return []string{
ansi.Faint(v.ClientID),
v.Name,
v.Type,
applyColor(v.Type),
}
}

Expand Down Expand Up @@ -305,3 +305,22 @@ func interfaceSliceToString(s []interface{}) []string {
}
return res
}

func applyColor(a string) string {
as-herzog marked this conversation as resolved.
Show resolved Hide resolved
switch {
case a == "machine to machine":
return ansi.Green(a)

case a == "native":
return ansi.Cyan(a)

case a == "single page application":
return ansi.Blue(a)

case a == "regular web application":
return ansi.Magenta(a)

default:
return a
}
}