diff --git a/cmd/environment.go b/cmd/environment.go index f42b7f10..2b82d7e7 100644 --- a/cmd/environment.go +++ b/cmd/environment.go @@ -164,7 +164,8 @@ func runEnvironmentList(cmd *cobra.Command, args []string) error { if env.Cost.Daily.Average.Amount != nil { daily = fmt.Sprintf("%v", *env.Cost.Daily.Average.Amount) } - tbl.AddRow(env.Slug, env.Name, env.Description, monthly, daily) + description := cli.TruncateString(env.Description, 60) + tbl.AddRow(env.Slug, env.Name, description, monthly, daily) } tbl.Print() diff --git a/cmd/project.go b/cmd/project.go index ea22c689..316fb9bb 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -171,7 +171,8 @@ func runProjectList(cmd *cobra.Command, args []string) error { if project.Cost.Daily.Average.Amount != nil { daily = fmt.Sprintf("%v", *project.Cost.Daily.Average.Amount) } - tbl.AddRow(project.Slug, project.Name, project.Description, monthly, daily) + description := cli.TruncateString(project.Description, 60) + tbl.AddRow(project.Slug, project.Name, description, monthly, daily) } tbl.Print() diff --git a/cmd/templates/environment.get.md.tmpl b/cmd/templates/environment.get.md.tmpl index 47094d8e..85acd62a 100644 --- a/cmd/templates/environment.get.md.tmpl +++ b/cmd/templates/environment.get.md.tmpl @@ -12,6 +12,6 @@ {{- end}} ## Cost -**Monthly Average:** {{with .Monthly.Average.Amount}}${{.}}{{end}} +**Monthly Average:** {{with .Cost.Monthly.Average.Amount}}${{.}}{{end}} -**Daily Average:** {{with .Daily.Average.Amount}}${{.}}{{end}} +**Daily Average:** {{with .Cost.Daily.Average.Amount}}${{.}}{{end}} diff --git a/cmd/templates/project.get.md.tmpl b/cmd/templates/project.get.md.tmpl index fbf0b846..4e7eb7d6 100644 --- a/cmd/templates/project.get.md.tmpl +++ b/cmd/templates/project.get.md.tmpl @@ -10,6 +10,6 @@ {{end}} ## Cost -**Monthly Average:** {{with .Monthly.Average.Amount}}${{.}}{{end}} +**Monthly Average:** {{with .Cost.Monthly.Average.Amount}}${{.}}{{end}} -**Daily Average:** {{with .Daily.Average.Amount}}${{.}}{{end}} +**Daily Average:** {{with .Cost.Daily.Average.Amount}}${{.}}{{end}} diff --git a/pkg/cli/table.go b/pkg/cli/table.go index 5f9f2524..8b881f17 100644 --- a/pkg/cli/table.go +++ b/pkg/cli/table.go @@ -2,6 +2,7 @@ package cli import ( "github.com/fatih/color" + "github.com/mattn/go-runewidth" "github.com/rodaine/table" ) @@ -14,3 +15,13 @@ func NewTable(headers ...any) table.Table { tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) return tbl } + +// TruncateString truncates a string to maxWidth runes, handling emojis correctly +func TruncateString(s string, maxWidth int) string { + if runewidth.StringWidth(s) <= maxWidth { + return s + } + // Truncate by rune width, not byte length + truncated := runewidth.Truncate(s, maxWidth, "...") + return truncated +}