mirror of https://github.com/databricks/cli.git
Do not use FgWhite and FgBlack for terminal output (#435)
## Changes Using white / black color for terminal output will lead to poorly displayed content in either light or dark terminal backgrounds. Some other CLIs experienced same issues (https://github.com/qri-io/qri/pull/774) Instead, let's just use color to highlight some of the output so it's more compatible with different background styles ## Tests <img width="772" alt="Screenshot 2023-06-05 at 16 05 09" src="https://github.com/databricks/cli/assets/2969996/01790239-6a33-4059-86a8-d5117ea0b75f"> --- <img width="757" alt="Screenshot 2023-06-05 at 16 05 20" src="https://github.com/databricks/cli/assets/2969996/ea3b9fdc-3782-4f4f-a9df-19e66af0c04f">
This commit is contained in:
parent
3dbf7a575a
commit
1f130f3722
|
@ -99,8 +99,8 @@ var profilesCmd = &cobra.Command{
|
||||||
Short: "Lists profiles from ~/.databrickscfg",
|
Short: "Lists profiles from ~/.databrickscfg",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"template": cmdio.Heredoc(`
|
"template": cmdio.Heredoc(`
|
||||||
{{white "Name"}} {{white "Host"}} {{white "Valid"}}
|
{{header "Name"}} {{header "Host"}} {{header "Valid"}}
|
||||||
{{range .Profiles}}{{.Name | green}} {{.Host|white}} {{bool .Valid}}
|
{{range .Profiles}}{{.Name | green}} {{.Host|cyan}} {{bool .Valid}}
|
||||||
{{end}}`),
|
{{end}}`),
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "Name"}} {{white "Type"}} {{white "Comment"}}
|
{{header "Name"}} {{header "Type"}} {{header "Comment"}}
|
||||||
{{range .}}{{.Name|green}} {{blue "%s" .CatalogType}} {{.Comment}}
|
{{range .}}{{.Name|green}} {{blue "%s" .CatalogType}} {{.Comment}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}} {{white "State"}}
|
{{header "ID"}} {{header "Name"}} {{header "State"}}
|
||||||
{{range .}}{{.ClusterId | green}} {{.ClusterName|white}} {{if eq .State "RUNNING"}}{{green "%s" .State}}{{else if eq .State "TERMINATED"}}{{red "%s" .State}}{{else}}{{blue "%s" .State}}{{end}}
|
{{range .}}{{.ClusterId | green}} {{.ClusterName | cyan}} {{if eq .State "RUNNING"}}{{green "%s" .State}}{{else if eq .State "TERMINATED"}}{{red "%s" .State}}{{else}}{{blue "%s" .State}}{{end}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
|
|
||||||
listNodeTypesCmd.Annotations["template"] = cmdio.Heredoc(`
|
listNodeTypesCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}}
|
{{header "ID"}} {{header "Name"}}
|
||||||
{{range .}}{{.Id|green}} {{.Name}}
|
{{range .}}{{.Id|green}} {{.Name}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "Name"}} {{white "Credential"}} {{white "URL"}}
|
{{header "Name"}} {{header "Credential"}} {{header "URL"}}
|
||||||
{{range .}}{{.Name|green}} {{.CredentialName|blue}} {{.Url}}
|
{{range .}}{{.Name|green}} {{.CredentialName|cyan}} {{.Url}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ func init() {
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
|
|
||||||
listRunsCmd.Annotations["template"] = cmdio.Heredoc(`
|
listRunsCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{"Job ID"|white}} {{"Run ID"|white}} {{"Result State"|white}} URL
|
{{header "Job ID"}} {{header "Run ID"}} {{header "Result State"}} URL
|
||||||
{{range .}}{{green "%d" .JobId}} {{blue "%d" .RunId}} {{if eq .State.ResultState "SUCCESS"}}{{"SUCCESS"|green}}{{else}}{{red "%s" .State.ResultState}}{{end}} {{.RunPageUrl}}
|
{{range .}}{{green "%d" .JobId}} {{cyan "%d" .RunId}} {{if eq .State.ResultState "SUCCESS"}}{{"SUCCESS"|green}}{{else}}{{red "%s" .State.ResultState}}{{end}} {{.RunPageUrl}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}} {{white "Region"}}
|
{{header "ID"}} {{header "Name"}} {{"Region"}}
|
||||||
{{range .}}{{.MetastoreId|green}} {{.Name|white}} {{.Region}}
|
{{range .}}{{.MetastoreId|green}} {{.Name|cyan}} {{.Region}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
func init() {
|
func init() {
|
||||||
// TODO: figure out colored/non-colored headers and colspan shifts
|
// TODO: figure out colored/non-colored headers and colspan shifts
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}} {{white "Author"}}
|
{{header "ID"}} {{header "Name"}} {{header "Author"}}
|
||||||
{{range .}}{{.Id|green}} {{.Name|white}} {{.User.Email|white}}
|
{{range .}}{{.Id|green}} {{.Name|cyan}} {{.User.Email|cyan}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
func init() {
|
func init() {
|
||||||
// TODO: figure out the right format
|
// TODO: figure out the right format
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{range .}}{{.UserName}} {{white "%s" .Status}} {{.QueryText}}
|
{{range .}}{{.UserName}} {{cyan "%s" .Status}} {{.QueryText}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "Full Name"}} {{white "Owner"}} {{white "Comment"}}
|
{{header "Full Name"}} {{header "Owner"}} {{header "Comment"}}
|
||||||
{{range .}}{{.FullName|green}} {{.Owner|white}} {{.Comment}}
|
{{range .}}{{.FullName|green}} {{.Owner|cyan}} {{.Comment}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listScopesCmd.Annotations["template"] = cmdio.Heredoc(`
|
listScopesCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "Scope"}} {{white "Backend Type"}}
|
{{header "Scope"}} {{header "Backend Type"}}
|
||||||
{{range .}}{{.Name|green}} {{.BackendType}}
|
{{range .}}{{.Name|green}} {{.BackendType}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}} {{white "Credentials"}}
|
{{header "ID"}} {{header "Name"}} {{header "Credentials"}}
|
||||||
{{range .}}{{.Id|green}} {{.Name|white}} {{if .AwsIamRole}}{{.AwsIamRole.RoleArn}}{{end}}{{if .AzureServicePrincipal}}{{.AzureServicePrincipal.ApplicationId}}{{end}}{{if .GcpServiceAccountKey}}{{.Email}}{{end}}
|
{{range .}}{{.Id|green}} {{.Name|cyan}} {{if .AwsIamRole}}{{.AwsIamRole.RoleArn}}{{end}}{{if .AzureServicePrincipal}}{{.AzureServicePrincipal.ApplicationId}}{{end}}{{if .GcpServiceAccountKey}}{{.Email}}{{end}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "Full Name"}} {{white "Table Type"}}
|
{{header "Full Name"}} {{header "Table Type"}}
|
||||||
{{range .}}{{.FullName|green}} {{blue "%s" .TableType}}
|
{{range .}}{{.FullName|green}} {{blue "%s" .TableType}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Created By"}} {{white "Comment"}}
|
{{header "ID"}} {{header "Created By"}} {{header "Comment"}}
|
||||||
{{range .}}{{.TokenId|green}} {{.CreatedByUsername|white}} {{.Comment|white}}
|
{{range .}}{{.TokenId|green}} {{.CreatedByUsername|cyan}} {{.Comment|cyan}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Expiry time"}} {{white "Comment"}}
|
{{header "ID"}} {{header "Expiry time"}} {{header "Comment"}}
|
||||||
{{range .}}{{.TokenId|green}} {{white "%d" .ExpiryTime}} {{.Comment|white}}
|
{{range .}}{{.TokenId|green}} {{cyan "%d" .ExpiryTime}} {{.Comment|cyan}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Name"}} {{white "Size"}} {{white "State"}}
|
{{header "ID"}} {{header "Name"}} {{header "Size"}} {{header "State"}}
|
||||||
{{range .}}{{.Id|green}} {{.Name|white}} {{.ClusterSize|white}} {{if eq .State "RUNNING"}}{{"RUNNING"|green}}{{else if eq .State "STOPPED"}}{{"STOPPED"|red}}{{else}}{{blue "%s" .State}}{{end}}
|
{{range .}}{{.Id|green}} {{.Name|cyan}} {{.ClusterSize|cyan}} {{if eq .State "RUNNING"}}{{"RUNNING"|green}}{{else if eq .State "STOPPED"}}{{"STOPPED"|red}}{{else}}{{blue "%s" .State}}{{end}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "github.com/databricks/cli/libs/cmdio"
|
||||||
func init() {
|
func init() {
|
||||||
listReq.Path = "/"
|
listReq.Path = "/"
|
||||||
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
listCmd.Annotations["template"] = cmdio.Heredoc(`
|
||||||
{{white "ID"}} {{white "Type"}} {{white "Language"}} {{white "Path"}}
|
{{header "ID"}} {{header "Type"}} {{header "Language"}} {{header "Path"}}
|
||||||
{{range .}}{{green "%d" .ObjectId}} {{blue "%s" .ObjectType}} {{cyan "%s" .Language}} {{.Path|white}}
|
{{range .}}{{green "%d" .ObjectId}} {{blue "%s" .ObjectType}} {{cyan "%s" .Language}} {{.Path|cyan}}
|
||||||
{{end}}`)
|
{{end}}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,7 @@ func renderTemplate(w io.Writer, tmpl string, v any) error {
|
||||||
// we render colored output if stdout is TTY, otherwise we render text.
|
// we render colored output if stdout is TTY, otherwise we render text.
|
||||||
// in the future we'll check if we can explicitly check for stderr being
|
// in the future we'll check if we can explicitly check for stderr being
|
||||||
// a TTY
|
// a TTY
|
||||||
"black": color.BlackString,
|
"header": color.BlueString,
|
||||||
"white": color.WhiteString,
|
|
||||||
"red": color.RedString,
|
"red": color.RedString,
|
||||||
"green": color.GreenString,
|
"green": color.GreenString,
|
||||||
"blue": color.BlueString,
|
"blue": color.BlueString,
|
||||||
|
@ -107,8 +106,9 @@ func fancyJSON(v any) ([]byte, error) {
|
||||||
f.FalseColor = color.New(color.FgRed)
|
f.FalseColor = color.New(color.FgRed)
|
||||||
f.NumberColor = color.New(color.FgCyan)
|
f.NumberColor = color.New(color.FgCyan)
|
||||||
f.NullColor = color.New(color.FgMagenta)
|
f.NullColor = color.New(color.FgMagenta)
|
||||||
f.FieldColor = color.New(color.FgWhite, color.Bold)
|
f.ObjectColor = color.New(color.Reset)
|
||||||
f.FieldQuoteColor = color.New(color.FgWhite)
|
f.CommaColor = color.New(color.Reset)
|
||||||
|
f.ColonColor = color.New(color.Reset)
|
||||||
|
|
||||||
return jsoncolor.MarshalIndentWithFormatter(v, "", " ", f)
|
return jsoncolor.MarshalIndentWithFormatter(v, "", " ", f)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue