Skip to content

Make table header bold #1106

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

Merged
merged 1 commit into from
Apr 9, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pkg/cli/configList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestConfigList(t *testing.T) {
t.Fatalf("ConfigList() error = %v", err)
}

expectedOutput := `Name
expectedOutput := "\x1b[1m\nName \x1b[0m" + `
foo
bar
`
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/cli/deploymentsList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestDeploymentsList(t *testing.T) {
if err != nil {
t.Fatalf("DeploymentsList() error = %v", err)
}
expectedOutput := `Deployment Provider DeployedAt
expectedOutput := "\x1b[1m\nDeployment Provider DeployedAt \x1b[0m" + `
a1b2c3 playground ` + timestamppb.Now().AsTime().Format("2006-01-02T15:04:05Z07:00") + `
`

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/cli/getServices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestGetServices(t *testing.T) {
if err != nil {
t.Fatalf("GetServices() error = %v", err)
}
expectedOutput := `Service Deployment PublicFqdn PrivateFqdn Status
expectedOutput := "\x1b[1m\nService Deployment PublicFqdn PrivateFqdn Status \x1b[0m" + `
foo a1b2c3 test-foo.prod1.defang.dev UNKNOWN
`

Expand Down
3 changes: 2 additions & 1 deletion src/pkg/term/colorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
WarnColor = termenv.ANSIYellow // not bright to improve readability on light backgrounds
DebugColor = termenv.ANSIBrightBlack // Gray

boldColorStr = termenv.CSI + termenv.BoldSeq + "m"
resetColorStr = termenv.CSI + termenv.ResetSeq + "m"
)

Expand Down Expand Up @@ -136,7 +137,7 @@ func output(w *termenv.Output, c Color, msg string) (int, error) {
}
var buf strings.Builder
if doColor(w) {
fprintc(&buf, doColor(w), c, msg)
fprintc(&buf, true, c, msg)
msg = buf.String() // this uses the buffer to avoid allocation, so make sure buf is not garbage collected
}
return w.WriteString(msg)
Expand Down
14 changes: 12 additions & 2 deletions src/pkg/term/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@ import (
)

func Table(slice interface{}, attributes []string) error {
return DefaultTerm.Table(slice, attributes...)
}

func (t *Term) Table(slice interface{}, attributes ...string) error {
// Ensure slice is a slice
val := reflect.ValueOf(slice)
if val.Kind() != reflect.Slice {
return errors.New("Table: input is not a slice")
}

// Create a tabwriter
w := tabwriter.NewWriter(DefaultTerm.stdout, 0, 0, 2, ' ', 0)
w := tabwriter.NewWriter(t.out, 0, 0, 2, ' ', 0)

var err error

var resetBold string
if t.StdoutCanColor() {
fmt.Fprintln(w, boldColorStr) // must be separate line or it will be counted as part of the 1st header
resetBold = resetColorStr
}

// Print headers
for _, attr := range attributes {
_, err = fmt.Fprintf(w, "%s\t", attr)
if err != nil {
return err
}
}
_, err = fmt.Fprintln(w)
_, err = fmt.Fprintln(w, resetBold)
if err != nil {
return err
}
Expand Down
Loading